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
cc39eba9
Commit
cc39eba9
authored
Jul 14, 2021
by
Kushal Pandya
Committed by
Evan Read
Jul 14, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docs: Add GraphQL Best Practices section within Frontend GraphQL
parent
de31a021
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
0 deletions
+29
-0
doc/development/fe_guide/graphql.md
doc/development/fe_guide/graphql.md
+29
-0
No files found.
doc/development/fe_guide/graphql.md
View file @
cc39eba9
...
...
@@ -906,6 +906,35 @@ apollo: {
},
```
### Best Practices
#### When to use (and not use) `update` hook in mutations
Apollo Client's
[
`.mutate()`
](
https://www.apollographql.com/docs/react/api/core/ApolloClient/#ApolloClient.mutate
)
method exposes an
`update`
hook that is invoked twice during the mutation lifecycle:
-
Once at the beginning. That is, before the mutation has completed.
-
Once after the mutation has completed.
You should use this hook only if you're adding or removing an item from the store
(that is, ApolloCache). If you're _updating_ an existing item, it is usually represented by
a global
`id`
.
In that case, presence of this
`id`
in your mutation query definition makes the store update
automatically. Here's an example of a typical mutation query with
`id`
present in it:
```
graphql
mutation
issueSetWeight
(
$input
:
IssueSetWeightInput
!)
{
issuableSetWeight
:
issueSetWeight
(
input
:
$input
)
{
issuable
:
issue
{
id
weight
}
errors
}
}
```
### Testing
#### Generating the GraphQL schema
...
...
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