Graphql queries: Difference between revisions

From wikinotes
Line 12: Line 12:
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">
# https://tracking-system/projects/1/graphql
{
{
   tasks($name: String){
   tasks($name: String){

Revision as of 00:35, 2 September 2021

Basics

Some fields may be implied by the REST API path, so no params are required.

# https://tracking-system/projects/1/graphql
{
  name
  createdAt
}

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"}

Without Params

With Params

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 items
  • numSeatbelts,numAirbags is queried on Car items
  • numSaddleBags is queried on Motorcycle items