Skip to content

default values for invisible arguments #5198

Open
@eapache-opslevel

Description

If you have an argument with a default_value:, and the argument is not visible for some reason, then the key (and thus default value) is not even present in the arguments hash. This is logically correct, but has caught us in a bug a couple of time where somebody will write, e.g.

argument :foo, Boolean, required: false, default_value: true, public: false

def resolve(**args)
  if args[:foo]
    # ...
  end
end

And then the wrong branch will execute when somebody runs against the public schema (i.e. with foo not visible) because it will be nil and interpreted as false instead of the desired "default" of true.

The current behaviour is correct/coherent, and there are a couple of obvious ways around this (e.g. listing out all of the args as kwargs to the resolve method, which requires duplicating all the default values and is annoying). But I wanted to ask in case anybody has a better pattern for avoiding this, or if the description of the problem prompts a clever idea for a solution.

It may not be spec-compliant / probably causes just as many problems as it solves, but injecting the default value even for invisible arguments is kind of the most "obvious" solution here.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions