Skip to content
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

Deprecate unsetFields Behavior #49

Merged
merged 5 commits into from
Apr 19, 2018
Merged

Deprecate unsetFields Behavior #49

merged 5 commits into from
Apr 19, 2018

Conversation

theorygeek
Copy link
Contributor

@theorygeek theorygeek commented Mar 8, 2018

When you use GraphQL::Models.define_mutator to help build a mutation, you are given two options for handling null input values:

  • :set_null will set any null input value to null
  • :leave_unchanged will leave any null input value alone. If you really meant to set it to null, you put the field's name into an array called unsetFields, and it will be set to null.

This somewhat odd behavior comes from the fact that at the time the gem was written, the GraphQL language did not have support for distinguishing between implicit and explicit null values. Well, support for that feature has been in GraphQL for a long time now.

This PR changes mutators so that they will respect the distinction between:

  • Providing a non-null value
  • Explicitly providing the value null
  • Implicitly not providing any value at all

If you explicitly provide the value null, the corresponding attribute on your model is set to nil. However, if you do not provide any value, the attribute is left unchanged.

This is now the default behavior for new mutations, but you can get back to the old behavior by either:

  • Using the argument legacy_nulls: true when defining your mutator, or
  • Setting GraphQL::Models.legacy_nulls = true before defining any mutators (ie, in an initializer)

TODO:

  • Update the readme
  • Update the release notes

@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|

spec.add_runtime_dependency "activesupport", ">= 4.2", '< 6'
spec.add_runtime_dependency "activerecord", ">= 4.2", '< 6'
spec.add_runtime_dependency "graphql", ">= 1.5.10", '< 2'
spec.add_runtime_dependency "graphql", ">= 1.7.5", '< 2'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theorygeek, just curiosity, is this what causes the change from type Foo implements Bar, Baz { field: Type } to type Foo implements Bar & Baz { field: Type } in the resulting schema?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably....

Copy link

@JhottMaster JhottMaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link

@JhottMaster JhottMaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@jongbeau jongbeau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@theorygeek - awesome

@theorygeek theorygeek merged commit 016fae5 into master Apr 19, 2018
@theorygeek theorygeek deleted the unset-fields branch April 19, 2018 15:14
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.

4 participants