Diagnose GraphQL query language
- In a GraphQL service we define our schema and then the incoming requests will be validated against it.
- Approaches in defining the schema:
- All-in-One Definition: define the schema directly in your code.
- Using Schema Definition Language (SDL): define schema in a separate file.
- Schema inferred from code: you have resolvers annotated with decorators, then a lib will generate the schema based on your code.
- Infer schema and resolver from the underlying database.
- GraphQL Object type
- A type with some fields.
- Field
-
Fields that can appear in any part of a GraphQL query that operates on the
Character
type. - List type
- An array of the specified type.
- Cannot define a non-empty list (an array with at least one member).
- A type modifier.
- Non-Null type
- The GraphQL service promises to give you a value whenever you query this field.
- A type modifier.
- Argument
- Arguments in GraphQL are passed by name specifically. Order does not matter!
- All arguments are named.
- Every field on a GraphQL Object type can have zero or more arguments.
- Can be required or optional.
Important
- Every GraphQL schema must support
query
operations. - The entry point of a "root" operation type is a regular Object type called
Query
by default.
-
Query
,Mutation
, andSubscription
are entry points of my GraphQL API.-
Note that they should start with a capital letter and the same name as they are listed here.
-
If you want to use a custom name, you can do it. But then you need to tell GraphQL about it:
type MySubscriptionType { todoStatusChange: Todo! } type MyMutationType { createTodo: Todo! } type MyQueryType { getTodos: [Todo] } schema { query: MyQueryType mutation: MyMutationType subscription: MySubscriptionType }
Learn more about Subscription here
-