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
f7f8d0a9
Commit
f7f8d0a9
authored
Oct 23, 2019
by
Bob Van Landuyt
Committed by
Sean McGivern
Oct 23, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Document finding objects by id in GraphQL
We prefer not exposing a database ID directly.
parent
069c6420
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
5 deletions
+12
-5
doc/development/api_graphql_styleguide.md
doc/development/api_graphql_styleguide.md
+12
-5
No files found.
doc/development/api_graphql_styleguide.md
View file @
f7f8d0a9
...
@@ -43,14 +43,14 @@ a new presenter specifically for GraphQL.
...
@@ -43,14 +43,14 @@ a new presenter specifically for GraphQL.
The presenter is initialized using the object resolved by a field, and
The presenter is initialized using the object resolved by a field, and
the context.
the context.
### Exposing Global
id
s
### Exposing Global
ID
s
When exposing an
`
id
`
field on a type, we will by default try to
When exposing an
`
ID
`
field on a type, we will by default try to
expose a global
id
by calling
`to_global_id`
on the resource being
expose a global
ID
by calling
`to_global_id`
on the resource being
rendered.
rendered.
To override this behaviour, you can implement an
`id`
method on the
To override this behaviour, you can implement an
`id`
method on the
type for which you are exposing an
id
. Please make sure that when
type for which you are exposing an
ID
. Please make sure that when
exposing a
`GraphQL::ID_TYPE`
using a custom method that it is
exposing a
`GraphQL::ID_TYPE`
using a custom method that it is
globally unique.
globally unique.
...
@@ -350,7 +350,10 @@ To find objects to display in a field, we can add resolvers to
...
@@ -350,7 +350,10 @@ To find objects to display in a field, we can add resolvers to
`app/graphql/resolvers`
.
`app/graphql/resolvers`
.
Arguments can be defined within the resolver, those arguments will be
Arguments can be defined within the resolver, those arguments will be
made available to the fields using the resolver.
made available to the fields using the resolver. When exposing a model
that had an internal ID (
`iid`
), prefer using that in combination with
the namespace path as arguments in a resolver over a database
ID. Othewise use a
[
globally unique ID
](
#exposing-global-ids
)
.
We already have a
`FullPathLoader`
that can be included in other
We already have a
`FullPathLoader`
that can be included in other
resolvers to quickly find Projects and Namespaces which will have a
resolvers to quickly find Projects and Namespaces which will have a
...
@@ -365,6 +368,10 @@ actions. In the same way a GET-request should not modify data, we
...
@@ -365,6 +368,10 @@ actions. In the same way a GET-request should not modify data, we
cannot modify data in a regular GraphQL-query. We can however in a
cannot modify data in a regular GraphQL-query. We can however in a
mutation.
mutation.
To find objects for a mutation, arguments need to be specified. As with
[
resolvers
](
#resolvers
)
, prefer using internal ID or, if needed, a
global ID rather than the database ID.
### Fields
### Fields
In the most common situations, a mutation would return 2 fields:
In the most common situations, a mutation would return 2 fields:
...
...
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