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
5dcabc34
Commit
5dcabc34
authored
Jun 16, 2020
by
Luke Duncalfe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GraphQL: Order mutation docs into sections
parent
1d375778
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
17 deletions
+27
-17
doc/development/api_graphql_styleguide.md
doc/development/api_graphql_styleguide.md
+27
-17
No files found.
doc/development/api_graphql_styleguide.md
View file @
5dcabc34
...
@@ -708,19 +708,6 @@ To find objects for a mutation, arguments need to be specified. As with
...
@@ -708,19 +708,6 @@ To find objects for a mutation, arguments need to be specified. As with
[
resolvers
](
#resolvers
)
, prefer using internal ID or, if needed, a
[
resolvers
](
#resolvers
)
, prefer using internal ID or, if needed, a
global ID rather than the database ID.
global ID rather than the database ID.
### Fields
In the most common situations, a mutation would return 2 fields:
-
The resource being modified
-
A list of errors explaining why the action could not be
performed. If the mutation succeeded, this list would be empty.
By inheriting any new mutations from
`Mutations::BaseMutation`
the
`errors`
field is automatically added. A
`clientMutationId`
field is
also added, this can be used by the client to identify the result of a
single mutation when multiple are performed within a single request.
### Building Mutations
### Building Mutations
Mutations live in
`app/graphql/mutations`
ideally grouped per
Mutations live in
`app/graphql/mutations`
ideally grouped per
...
@@ -728,12 +715,16 @@ resources they are mutating, similar to our services. They should
...
@@ -728,12 +715,16 @@ resources they are mutating, similar to our services. They should
inherit
`Mutations::BaseMutation`
. The fields defined on the mutation
inherit
`Mutations::BaseMutation`
. The fields defined on the mutation
will be returned as the result of the mutation.
will be returned as the result of the mutation.
### Naming conventions
Always provide a consistent GraphQL-name to the mutation, this name is
Always provide a consistent GraphQL-name to the mutation, this name is
used to generate the input types and the field the mutation is mounted
used to generate the input types and the field the mutation is mounted
on. The name should look like
`<Resource being modified><Mutation
on. The name should look like
`<Resource being modified><Mutation
class name>`
, for example the
`Mutations::MergeRequests::SetWip`
class name>`
, for example the
`Mutations::MergeRequests::SetWip`
mutation has GraphQL name
`MergeRequestSetWip`
.
mutation has GraphQL name
`MergeRequestSetWip`
.
### Arguments
Arguments required by the mutation can be defined as arguments
Arguments required by the mutation can be defined as arguments
required for a field. These will be wrapped up in an input type for
required for a field. These will be wrapped up in an input type for
the mutation. For example, the
`Mutations::MergeRequests::SetWip`
the mutation. For example, the
`Mutations::MergeRequests::SetWip`
...
@@ -762,11 +753,28 @@ This would automatically generate an input type called
...
@@ -762,11 +753,28 @@ This would automatically generate an input type called
`clientMutationId`
.
`clientMutationId`
.
These arguments are then passed to the
`resolve`
method of a mutation
These arguments are then passed to the
`resolve`
method of a mutation
as keyword arguments. From here, we can call the service that will
as keyword arguments.
modify the resource.
### Fields
In the most common situations, a mutation would return 2 fields:
-
The resource being modified
-
A list of errors explaining why the action could not be
performed. If the mutation succeeded, this list would be empty.
By inheriting any new mutations from
`Mutations::BaseMutation`
the
`errors`
field is automatically added. A
`clientMutationId`
field is
also added, this can be used by the client to identify the result of a
single mutation when multiple are performed within a single request.
### The `resolve` method
The
`resolve`
method receives the mutation's arguments as keyword arguments.
From here, we can call the service that will modify the resource.
The
`resolve`
method should then return a hash with the same field
The
`resolve`
method should then return a hash with the same field
names as defined on the mutation
and
an
`errors`
array. For example,
names as defined on the mutation
including
an
`errors`
array. For example,
the
`Mutations::MergeRequests::SetWip`
defines a
`merge_request`
the
`Mutations::MergeRequests::SetWip`
defines a
`merge_request`
field:
field:
...
@@ -791,7 +799,9 @@ should look like this:
...
@@ -791,7 +799,9 @@ should look like this:
}
}
```
```
To make the mutation available it should be defined on the mutation
### Mounting the mutation
To make the mutation available it must be defined on the mutation
type that lives in
`graphql/types/mutation_types`
. The
type that lives in
`graphql/types/mutation_types`
. The
`mount_mutation`
helper method will define a field based on the
`mount_mutation`
helper method will define a field based on the
GraphQL-name of the mutation:
GraphQL-name of the mutation:
...
...
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