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.
Why are we making this change?
In #1000 & #1004 a user is wanting to build a query that doesn't make use of variables without hardcoding the values of arguments. This is to make use of some shopify functionality that requires you to submit a query without variables.
My initial instinct was that this should be done externally to cynic, but I did plan on documenting how. #1007 was added to cater to this - it contained an example that used the
graphql-query
crate to post-process a cynic query and inline all of the variables into arguments in the query.However, when writing this I discovered it's not quite as smooth as I'd hoped: you can't just dump the variables into JSON and put those into the query because enums are serialised as strings in JSON but enum format in GraphQL. Being unable to use JSON means you're also unable to dynamically look up variables from their names - you have to hardcode every variable that you want to substitute. Which is pretty crap.
What effects does this change have?
This PR introduces a new
QueryVariableLiterals
trait & derive that aims to help with this: it exposes a single functionget
that can be passed the name of a variable and it will return the appropriateInputLiteral
for that variable.This can be used to make a
graphql-query
based transform much nicer, but it should also make it easy enough to add support for variable inlining into cynic itself.