Lifecycle of a request
[!NOTE]
You can see this YouTube video after you read this doc or before it to get the most out of them:
- Document parsing:
- AKA Lexing and Parsing.
- Transform the query (which is string) into something it understands.
- Validation using the type system: is it valid when checked against the API’s schema?
- Execution.
- Mirror the returned data from resolver into the requested shape.
- GraphQL place each resolved field into a key-value map with the field name (or alias) as the key and the resolved value as the value.
- It starts from leaves and works its way back up to the root (this why our responses resemble our requests).
- Scalar coercion converts values into the types expected by the schema (e.g.
enums will be coerced). - GraphQL waits for promises to be resolved before trying to construct the response (just look at my
createUserresolver, I do NOT haveawaitand it is working just fine).
- Return response:
- GraphQL returns a JSON as a response for query operation which contains:
- A
datakey: - An
errorkey:- Learn about different reasons that an error might occur here.
- An
extensionkey:- No restriction on what can goes inside it.
- Spec only tell that it can be sent back as a top-level key.
- Depends on the GraphQL implementation.
- Can contain additional info about response, things like:
- A
- At least one of
dataorerrorswill be present on the response.
- GraphQL returns a JSON as a response for query operation which contains: