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
2adf31e4
Commit
2adf31e4
authored
May 20, 2020
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[DOC] Add information about the use of ready?
parent
c5dfe519
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
1 deletion
+26
-1
doc/development/api_graphql_styleguide.md
doc/development/api_graphql_styleguide.md
+26
-1
No files found.
doc/development/api_graphql_styleguide.md
View file @
2adf31e4
...
...
@@ -619,6 +619,31 @@ lot of dependent objects.
To limit the amount of queries performed, we can use
`BatchLoader`
.
### Correct use of `Resolver#ready?`
Resolvers have two public API methods as part of the framework:
`#ready?(**args)`
and
`#resolve(**args)`
.
We can use
`#ready?`
to perform set-up, validation or early-return without invoking
`#resolve`
.
Good reasons to use
`#ready?`
include:
-
validating mutually exclusive arguments (see
[
validating arguments
](
#validating-arguments
)
)
-
Returning
`Relation.none`
if we know before-hand that no results are possible
-
Performing setup such as initializing instance variables (although consider lazily initialized methods for this)
Implementations of
[
`Resolver#ready?(**args)`
](
https://graphql-ruby.org/api-doc/1.10.9/GraphQL/Schema/Resolver#ready%3F-instance_method
)
should
return
`(Boolean, early_return_data)`
as follows:
```
ruby
def
ready?
(
**
args
)
[
false
,
'have this instead'
]
end
```
For this reason, whenever you call a resolver (mainly in tests - as framework
abstractions Resolvers should not be considered re-usable, finders are to be
preferred), remember to call the
`ready?`
method and check the boolean flag
before calling
`resolve`
!
## Mutations
Mutations are used to change any stored values, or to trigger
...
...
@@ -785,7 +810,7 @@ def ready?(**args)
end
# Always remember to call `#super`
super
(
args
)
super
end
```
...
...
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