Taking into account Apollo fragment interpolation#33
Merged
helfer merged 2 commits intoapollographql:masterfrom Jan 23, 2017
Merged
Taking into account Apollo fragment interpolation#33helfer merged 2 commits intoapollographql:masterfrom
helfer merged 2 commits intoapollographql:masterfrom
Conversation
Contributor
Author
|
I had one question - this affects the default behavior of the |
Contributor
|
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. |
Contributor
Author
Contributor
|
@jnwng Sorry this slipped under my radar. Looks good to me, I'll merge it and release a new version! |
Contributor
|
0.5.0 published. Thank you all for your patience, and special thanks to @jonwong for fixing this! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is attempting to resolve #29.
In Apollo, fragment interpolation is now valid within the
gqlTaggedTemplateLiteral, but only outside of top-level structures likequeryormutation. 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-tagitself, allowing one to interpolate fragments directly into queries themselves, like so:However,
eslint-plugin-graphqlwill report this as a warning / error because interpolation was previously not valid ingqlqueries for the Apollo client.