Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b46deaeb
Commit
b46deaeb
authored
Feb 26, 2020
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GraphQL fields should generally be nullable
parent
becfc8bc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
doc/development/api_graphql_styleguide.md
doc/development/api_graphql_styleguide.md
+22
-0
No files found.
doc/development/api_graphql_styleguide.md
View file @
b46deaeb
...
...
@@ -76,6 +76,28 @@ a new presenter specifically for GraphQL.
The presenter is initialized using the object resolved by a field, and
the context.
### Nullable fields
GraphQL allows fields to be be "nullable" or "non-nullable". The former means
that
`null`
may be returned instead of a value of the specified type.
**
In
general
**
, you should prefer using nullable fields to non-nullable ones, for
the following reasons:
-
It's common for data to switch from required to not-required, and back again
-
Even when there is no prospect of a field becoming optional, it may not be
**available**
at query time
-
For instance, the
`content`
of a blob may need to be looked up from Gitaly
-
If the
`content`
is nullable, we can return a
**partial**
response, instead of failing the whole query
-
Changing from a non-nullable field to a nullable field is difficult with a versionless schema
Non-nullable fields should only be used when a field is required, very unlikely
to become optional in the future, and very easy to calculate. An example would
be
`id`
fields.
Further reading:
-
[
GraphQL Best Practices Guide
](
https://graphql.org/learn/best-practices/#nullability
)
-
[
Using nullability in GraphQL
](
https://blog.apollographql.com/using-nullability-in-graphql-2254f84c4ed7
)
### Exposing Global IDs
When exposing an
`ID`
field on a type, we will by default try to
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment