-
Notifications
You must be signed in to change notification settings - Fork 1.5k
link to variables section in fragments section #541
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
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
site/learn/Learn-Queries.md
Outdated
@@ -122,7 +122,7 @@ fragment comparisonFields on Character { | |||
} | |||
``` | |||
|
|||
You can see how the above query would be pretty repetitive if the fields were repeated. The concept of fragments is frequently used to split complicated application data requirements into smaller chunks, especially when you need to combine lots of UI components with different fragments into one initial data fetch. | |||
You can see how the above query would be pretty repetitive if the fields were repeated. The concept of fragments is frequently used to split complicated application data requirements into smaller chunks, especially when you need to combine lots of UI components with different fragments into one initial data fetch. Much like other `type` declarations, `fragment`s can use [variables](learn/queries/#variables). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments:
- I don't think "type declaration" is the right set of words here, since that sounds like it refers to the schema language (
type Person { ... }
) and not queries/mutations. - This skips over the fact that fragment variables work pretty differently than queries/mutations, since they depend on the query inside which the fragment is used. I think it might be good to add an example here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the response. Is there a query example that I could borrow from with the star wars schema? I am unfamiliar with the graphql markdown.
What I would like to do is something like:
fragment comparisonFields on Character {
name
appearsIn
friends(droid: $droid) {
name
}
}
query HeroComparison($droid: Boolean) {
leftComparison: hero(episode: EMPIRE) {
...comparisonFields
}
rightComparison: hero(episode: JEDI) {
...comparisonFields
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if you look a little higher in the file you'll see how to do it:
```graphql
# { "graphiql": true }
{
leftComparison: hero(episode: EMPIRE) {
...comparisonFields
}
rightComparison: hero(episode: JEDI) {
...comparisonFields
}
}
fragment comparisonFields on Character {
name
appearsIn
friends {
name
}
}
```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I'm asking specifically is if I can just add a variable like droid
in the query, or if the graphiql markdown is really driven by a schema, which would result in an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ohhh, yes there is a schema, it's here: https://github.com/graphql/graphql.github.io/blob/source/site/_core/swapiSchema.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I'll take a look and update my commit.
Thanks! |
* link to variables section in fragments section * add fragment with argument example * reference variables instead of arguments
As someone new to graphql, it was not clear to me that I could use variables inside of a fragment given the fragment example.
This will hopefully help others with similar confusion.