-
Notifications
You must be signed in to change notification settings - Fork 103
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
Taking into account Apollo fragment interpolation #33
Conversation
I had one question - this affects the default behavior of the |
Yeah let's make the default compatible with 'graphql-tag' in general. |
In Apollo, fragment interpolation is now valid within the `gql` TaggedTemplateLiteral, but only outside of top-level structures like `query` or `mutation`. In other clients like Lokka and Relay, fragment interpolation actuall results in a text substitution, but in Apollo this gets evaluated at runtime, so we only need to validate the location of the fragment interpolation.
Making sure to check the invalid fragment or variable case in other environments, as well as ensuring that the default env works similar to how Apollo does.
1eba826
to
3cbddfb
Compare
bump |
fwiw, I tried in the #eslint-plugin-graphql channel. Then to work around this I forked, merged jnwng:jw/apollo-fragments, and published a private package. |
@jnwng Sorry this slipped under my radar. Looks good to me, I'll merge it and release a new version! |
0.5.0 published. Thank you all for your patience, and special thanks to @jonwong for fixing this! |
This PR is attempting to resolve #29.
In Apollo, fragment interpolation is now valid within the
gql
TaggedTemplateLiteral, but only outside of top-level structures likequery
ormutation
. In other clients like Lokka and Relay, fragment interpolation actually results in a document substitution, but in Apollo this gets evaluated at runtime, so we only need to validate the location of the fragment interpolation.We'll do this by evaluating two things:
In Apollo, fragment interpolation is invalid inside of query structures, so a document like this should fail:
NOTE: the evaluation strategy for checking to see if we're outside of a structure is naively evaluating the number of open and closing brackets, not whether or not they're matching. this means that
won't throw an error for invalid interpolation (but the graphql parser itself will throw an error on the invalid document structure). this just seemed easier to do.
Update CHANGELOG.md with your change(omitted because I'm not fully sure I should be doing this)Add your name and email to the AUTHORS file (optional)(omitted because this file does not exist)If this was a change that affects the external API, update the docs and post a link to the PR in the discussion(omitted because it does not change an external API)Steps to Reproduce
Recently, graphql-fragments was deprecated and its functionality baked into
graphql-tag
itself, allowing one to interpolate fragments directly into queries themselves, like so:However,
eslint-plugin-graphql
will report this as a warning / error because interpolation was previously not valid ingql
queries for the Apollo client.