Validate GraphQL Query
Learn how the GraphQL server validates queries from the client.
We'll cover the following...
By leveraging the type system, we can determine the validity of any query. The system allows servers and clients to notify developers when they send GraphQL queries without relying on runtime checks.
Can’t spread fragment
A fragment can’t refer to itself since this could cause an unbounded result. Here’s the pizzas
query with an invalid GraphQL fragment:
Press + to interact
query GetPizzas {Neapolitan: pizzas(name: "Neapolitan Pizza") {...pizzaFields}Chicago: pizzas(name: "Chicago Pizza") {...pizzaFields}}fragment pizzaFields on Pizza {... on Pizza {idpizza}... on ChicagoPizza {...pizzaFields // this is invalid!}}
If we execute the query, we’ll receive the following error:
{
...