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

Make sure there's a Query node before trying to add a field to it. #1010

Merged
merged 1 commit into from
Feb 5, 2020

Conversation

csilvers
Copy link
Contributor

@csilvers csilvers commented Feb 5, 2020

Federation adds some queries to the schema. There already existed
code to insert a Query node if none existed previously. But that code
was only put on addEntityToSchema(), and not the other place we update
the query, addServiceToSchema().

Almost always the old code was good enough, since we call
addEntityToSchema() before addServiceToSchema(). But there's on
exception: when the schema has no @key. In that case we only call
addServiceToSchema(), so we need to do the query-existence check there
too.

Describe your PR and link to any relevant issues.

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

Federation adds some queries to the schema.  There already existed
code to insert a Query node if none existed previously.  But that code
was only put on addEntityToSchema(), and not the other place we update
the query, addServiceToSchema().

Almost always the old code was good enough, since we call
addEntityToSchema() before addServiceToSchema().  But there's on
exception: when the schema has no `@key`.  In that case we only call
addServiceToSchema(), so we need to do the query-existence check there
too.
@csilvers
Copy link
Contributor Author

csilvers commented Feb 5, 2020

@marwan-at-work -- this is appropriate for you to review I think.

This fixes a bug from my last PR (that allowed code to work without a @key field). It fixes the even rarer case that there's no @key field and there's no Query.

@csilvers
Copy link
Contributor Author

csilvers commented Feb 5, 2020

(Also, I can't figure out a good way to test MutateSchema -- if you know of one, let me know!)

@coveralls
Copy link

Coverage Status

Coverage increased (+0.02%) to 65.791% when pulling 9f2a624 on Khan:query-exists into b941b97 on 99designs:master.

Copy link
Contributor

@marwan-at-work marwan-at-work left a comment

Choose a reason for hiding this comment

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

LGTM :)

@vektah
Copy link
Collaborator

vektah commented Feb 5, 2020

Sweet, good to see this getting some polish before 0.11 👍

@vektah vektah merged commit b4a00e6 into 99designs:master Feb 5, 2020
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
Make sure there's a Query node before trying to add a field to it.
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