Graphql queries: Difference between revisions
From wikinotes
(→Basics) |
No edit summary |
||
Line 1: | Line 1: | ||
= Basics = | = Basics = | ||
<blockquote> | |||
</blockquote><!-- Basics --> | |||
= Without Params = | |||
<blockquote> | <blockquote> | ||
Some fields may be implied by the REST API path, so no params are required. | Some fields may be implied by the REST API path, so no params are required. | ||
Line 10: | Line 15: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Without Params --> | |||
= With Params = | |||
<blockquote> | |||
Other times, you may need to use parameters in your query. | Other times, you may need to use parameters in your query. | ||
<syntaxhighlight lang="graphql"> | <syntaxhighlight lang="graphql"> | ||
Line 24: | Line 33: | ||
{"name": "clean bathroom"} | {"name": "clean bathroom"} | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- With Params --> | </blockquote><!-- With Params --> | ||
Revision as of 00:37, 2 September 2021
Basics
Without Params
Some fields may be implied by the REST API path, so no params are required.
# https://tracking-system/projects/1/graphql { name createdAt }
With Params
Other times, you may need to use parameters in your query.
# https://tracking-system/projects/1/graphql { tasks($name: String){ status createdAt } }{"name": "clean bathroom"}
Fragments
TODO:
Example schema
When a collection can contain multiple types,
fragments let you select different fields for different types.{ rentalInventory { vehicles { wheels passengers ... on Car { numSeatbelts numAirbags } ... on Motorcycle { numSaddleBags } } } }
wheels, passengers
are queried on all itemsnumSeatbelts,numAirbags
is queried onCar
itemsnumSaddleBags
is queried onMotorcycle
items