Graphql queries: Difference between revisions

From wikinotes
(Created page with "= Basics = <blockquote> </blockquote><!-- Basics --> = Without Params = <blockquote> </blockquote><!-- Without Params --> = With Params = <blockquote> </blockquote><!-- W...")
 
Line 16: Line 16:
= Fragments =
= Fragments =
<blockquote>
<blockquote>
{{ TODO |
Example schema }}


When a collection can contain multiple types,<br>
fragments let you select different fields for different types.
<syntaxhighlight lang="graphql">
{
  rentalInventory {
    vehicles {
      wheels
      passengers
      ... on Car {
        numSeatbelts
        numAirbags
      }
      ... on Motorcycle {
        numSaddleBags
      }
    }
  }
}
</syntaxhighlight>
* <code>wheels, passengers</code> are queried on all items
* <code>numSeatbelts,numAirbags</code> is queried on <code>Car</code> items
* <code>numSaddleBags</code> is queried on <code>Motorcycle</code> items
</blockquote><!-- Fragments -->
</blockquote><!-- Fragments -->

Revision as of 00:20, 2 September 2021

Basics

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