type Example { foo: Foo! bar: Bar! }
Optional and Required Fields
Lists
Preferably, don’t use nested lists. Using deeply nested lists breaks schema introspection since even schema introspection can’t circumvent the constant depth recursion that’s imposed on query execution in GraphQL.
Unique Identification
We recommend that every non-trivial type has a unique identifier. This helps GraphQL clients on frontend build their cache and will give you automatic UI updates in return. While it’s not explicitly mentioned in the GraphQL spec, we recommend adding a field called
id
of non-nullable type ID
. All GraphQL clients recognize this field and use it for client-side caching.id: ID!
Arguments
Fields that you define on a object type, may be passed arguments.
extend type Query { greeting(name: String!): String! }
When you’re writing your argument definition, Litho will make sure to only suggest types that are suitable for use as an argument type. Since only input types are allowed, object types are automatically excluded from the list of suggestions.
Arguments with Default Values
Common Errors
E0100
Named type must exist.
This error is emitted when you reference a type that doesn’t exist.
In the example below type
Foo
references a type named Bar
but it’s not defined.type Foo { bar: Bar! }
E0101
Type must define one or more fields.
Every type in GraphQL most define at least one field at some point (including type extensions).
The example below does not compile because type
Foo
doesn’t have any fields.type Foo
E0102
Field name must be unique.
Every field in a GraphQL type must have a unique name, even when they have the same type.
The example below does not compile because field
foo
is defined twice.type Foo { foo: String! }
E0103
Field name must be unique across extended types.
Extended fields must have a name that is unique in both the base type and every other extension on that type.
For example, the following does not compile because field
foo
is defined both in the base type and the extension.type Foo { foo: String! } extend type Foo { foo: String! }
Another, slightly more complicated example that triggers this error is when we define the same field
bar
in two different type extensions (which is not allowed).type Foo { foo: String! } extend type Foo { bar: String! } extend type Foo { bar: String! }
Â
Â