Check for null FieldNode directives and add Apollo Link usage example #13
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.
One of these changes relies on the other one to work so I thought it'd be easiest to roll them into the same PR.
The first commit just checks if
node.directives
is falsy before iterating over it, because it looks from the type definitions like thedirectives
prop is optional.The second commit adds an example of how you could use an Apollo Link, a sort of query fetching middleware, to apply the graphql-lodash transformation, which I believe is the recommended Apollo way of manipulating queries and responses like this. Since every query/mutation/subscription is run by Apollo by feeding it through the Apollo Client's chain of Links, I believe this also fixes #12.
However, using a Link like this with Apollo relies on the null
directives
check. This is because Apollo adds a__typename
field to every object type in the outgoing query, but leaves the directives undefined instead of setting them to[]
asgraphql()
does, so you would get:I also added a remark to the README on how you can extend the introspection query results to add the graphql-lodash directives, which could be important for certain applications. For instance, I figured out how to do this by reading your
demo/
app while trying to integrate this library with graphql-playground, which uses Apollo Links for query fetching.