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

Fix breaking change messages for root schema type changes/additions #55

Conversation

willlockwood
Copy link
Contributor

As part of our work using graphql-schema_comparator, we've been using the schema comparator in our test suite to add visibility to when developers propose breaking changes to our schema. Recently, we added a mutation root type to a schema that previous didn't have one, and were surprised to see that as a breaking change, and to see the breaking change message using a string representation of the mutation root type itself (meaning that the message itself was not a stable description of the change, but would change every time our test was run):

Schema mutation root has changed from `` to #<Class:0x00007fd9879d8858>

This PR does two things:

  • It adds new non-breaking changes for when root schema types (query, mutation, subscription) are added
  • Modifies the descriptions of the query/mutation/subscription type changed changes to refer to the graphql_names of the types, rather than a string representation of the type class, and
  • Fixes another error that was causing the tests to fail, around the names of default values for arguments

@willlockwood willlockwood marked this pull request as ready for review October 17, 2023 19:39
@willlockwood
Copy link
Contributor Author

cc @xuorig and @swalkinshaw not exactly sure who I should be tagging but I see y'all in the code—got a bit of a fix here to some minor issues, let me know if there's anything I can do to make it easy to get the fixes in (or if there's anyone else I should be pinging for review) and I'll be happy to do so!

@@ -414,11 +434,31 @@ def initialize(old_schema, new_schema)
end

def message
"Schema mutation root has changed from `#{old_schema.mutation}` to `#{new_schema.mutation}`"
"Schema mutation root has changed from `#{old_schema.mutation.graphql_name}` to `#{new_schema.mutation&.graphql_name}`"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same question about the safe operator usage here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So here, I think the null safe operator is necessary—this basically covers the case where someone removes a mutation root altogether (instead of changing/renaming it). I just verified that this was also a possible breakage on the schema query/subscription type changed classes, so I added it in there as well. I figured, it would be better to just make these changes null-safe, rather than add a set of SchemaQueryTypeRemoved/SchemaMutationTypeRemoved/SchemaSubscriptionTypeRemoved changes as well.

Let me know if that makes sense to you as well—thank you for taking a look!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another alternative is unifying these into "root operation" changes:

  • RootOperationTypeRemoved
  • RootOperationTypeAdded
  • RootOperationTypeChanged

Messaging could be "Schema root operation type mutation changed from {} to {}`".

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that makes a lot of sense. Just put those changes in—thanks for the review/suggestion!

Comment on lines -461 to +524
"Default value `#{new_argument.default_value}` was added to argument `#{new_argument.graphql_name}` on field `#{field.path}`"
else
if old_argument.default_value?
"Default value for argument `#{new_argument.graphql_name}` on field `#{field.path}` changed"\
" from `#{old_argument.default_value}` to `#{new_argument.default_value}`"
else
"Default value `#{new_argument.default_value}` was added to argument `#{new_argument.graphql_name}` on field `#{field.path}`"
Copy link
Contributor Author

@willlockwood willlockwood Oct 17, 2023

Choose a reason for hiding this comment

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

Also, just a heads up about these default value changes—I updated these because the tests were failing on newer versions of graphql-ruby, that don't rely on :__no_default__ to specify no default argument value.

These changes only really are only necessary if you're running a later version of graphql-ruby—if you'd like me to make these changes separately and also set up a new gemfile specifically to run the test suite on graphql-ruby 2.1, let me know and I'd be happy to pull these changes out of this PR and do that as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice improvement 👍 default_value? has actually been around forever so we can safely use that: rmosolgo/graphql-ruby@23a467d

It's just that __no_default__ was only removed in 2.1 I guess.

@swalkinshaw
Copy link
Collaborator

Thanks for the improvement @willlockwood

@swalkinshaw swalkinshaw merged commit 212f1f1 into xuorig:master Oct 18, 2023
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