Skip to content

Apply default values that are 'false' #658

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 6, 2017

Conversation

jamesdphillips
Copy link
Contributor

Unless I'm mistaking the intent it appears I've encountered an issue with false default_values not being applied. I believe this is because the conditional in InputObjectType checks that the coerced value is falsey and not explicitly nil, meaning that false values are being left behind.

See attached patch for (what I suspect) is the correct behaviour. I think my test might be a bit flimsy so I'm open to suggestions. =)

Thanks!

Current Behavior

  IntroduceShipMutation = GraphQL::Relay::Mutation.define do
    name "IntroduceShip"
    description "Add a ship to this faction"

    input_field :isCoolShip, types.Boolean, default_value: false
    return_type types.Boolean

    resolve ->(_, inputs, _) { inputs[:isCoolShip] }
  end
  • Considering the above mutation when called with variables { "clientMutationId": "xxx" } the result is nil.
  • Considering the above mutation when called with variables { "clientMutationId": "xxx", "isCoolShip": null } the result is nil.
  • Considering the above mutation when called with variables { "clientMutationId": "xxx", "isCoolShip": false } the result is false.
  • Considering the above mutation when called with variables { "clientMutationId": "xxx", "isCoolShip": true } the result is true.

Anomaly

It's also worth noting that inline variables are unaffected. For instance if I ran the following query the result would be false. Seemingly relevant snippet.

mutation {
  introduceShipMutation(input: { clientMutationId: "xxx" }) # result would be false
}

Expected Behavior

  IntroduceShipMutation = GraphQL::Relay::Mutation.define do
    name "IntroduceShip"
    description "Add a ship to this faction"

    input_field :isCoolShip, types.Boolean, default_value: false
    return_type types.Boolean

    resolve ->(_, inputs, _) { inputs[:isCoolShip] }
  end
  • Considering the above mutation when called with variables { "clientMutationId": "xxx" } the result is false.
  • Considering the above mutation when called with variables { "clientMutationId": "xxx", "isCoolShip": null } the result is false.
  • Considering the above mutation when called with variables { "clientMutationId": "xxx", "isCoolShip": false } the result is false.
  • Considering the above mutation when called with variables { "clientMutationId": "xxx", "isCoolShip": true } the result is true.

@rmosolgo
Copy link
Owner

rmosolgo commented Apr 6, 2017

👍 thanks for hunting this down!

@rmosolgo rmosolgo merged commit f3d5397 into rmosolgo:master Apr 6, 2017
@jamesdphillips
Copy link
Contributor Author

Thanks! 🎉

@jamesdphillips jamesdphillips deleted the falsey-default-values-bug branch April 6, 2017 21:58
@rmosolgo rmosolgo modified the milestone: 1.5.6 Apr 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants