|
1 | 1 | # Validation
|
2 | 2 |
|
3 |
| -GraphQL does not just verify if a request is syntactically correct. |
4 |
| - |
5 |
| -Prior to execution, it can also verify that a request is valid |
6 |
| -within the context of a given GraphQL schema. Validation is primarily |
7 |
| -targeted at development-time tooling. Any client-side tooling |
8 |
| -should return errors and not allow the formulation of queries |
9 |
| -known to violate the type system at a given point in time. |
10 |
| - |
11 |
| -Total request validation on the server-side during execution is optional. As |
12 |
| -schemas and systems change over time existing clients may end up emitting |
13 |
| -queries that are no longer valid given the current type system. Servers |
14 |
| -(as described in the Execution section of this spec) attempt to satisfy as |
15 |
| -much of the request as possible and continue to execute in the presence |
16 |
| -of type system errors rather than cease execution completely. |
| 3 | +GraphQL does not just verify if a request is syntactically correct, but also |
| 4 | +ensures that it is unambiguous and mistake-free in the context of a given |
| 5 | +GraphQL schema. |
| 6 | + |
| 7 | +An invalid request is still technically executable, and will always produce a |
| 8 | +stable result as defined by the procedures in the Execution section, however |
| 9 | +that result may be ambiguous, surprising, or unexpected relative to the request |
| 10 | +containing validation errors, so execution should not occur for invalid requests. |
| 11 | + |
| 12 | +Typically validation is performed in the context of a request immediately |
| 13 | +before execution, however a GraphQL service may execute a request without |
| 14 | +explicitly validating it if that exact same request is known to have been |
| 15 | +validated before. For example: the request may be validated during development, |
| 16 | +provided it does not later change, or a service may validate a request once and |
| 17 | +memoize the result to avoid validating the same request again in the future. |
| 18 | +Any client-side or development-time tool should report validation errors and not |
| 19 | +allow the formulation or execution of requests known to be invalid at that given |
| 20 | +point in time. |
| 21 | + |
| 22 | +**Type system evolution** |
| 23 | + |
| 24 | +As GraphQL type system schema evolve over time by adding new types and new |
| 25 | +fields, it is possible that a request which was previously valid could later |
| 26 | +become invalid. Any change that can cause a previously valid request to become |
| 27 | +invalid is considered a *breaking change*. GraphQL services and schema |
| 28 | +maintainers are encouraged to avoid breaking changes, however in order to be |
| 29 | +more resilient to these breaking changes, sophisticated GraphQL systems may |
| 30 | +still allow for the execution of requests which *at some point* were known to |
| 31 | +be free of any validation errors, and have not changed since. |
| 32 | + |
| 33 | +**Examples** |
17 | 34 |
|
18 | 35 | For this section of this schema, we will assume the following type system
|
19 | 36 | in order to demonstrate examples:
|
|
0 commit comments