rmosolgo / rmosolgo/graphql-ruby

default values for invisible arguments

Open
#5,198 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
5.4k
Forks
1.4k
Avg merge
23h 19m
Merged PRs (30d)
28

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No file, test, or entry point is named. Start by reproducing the public-schema example with an invisible argument using default_value, then trace how the arguments hash is built. Done requires a decided, documented behavior and tests covering invisible arguments and their defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
graphql, ruby
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.