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
20bf7c6d
Commit
20bf7c6d
authored
Mar 12, 2020
by
Luke Duncalfe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add argument validation to GraphQL Styleguide
parent
5ea90fa9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
0 deletions
+31
-0
doc/development/api_graphql_styleguide.md
doc/development/api_graphql_styleguide.md
+31
-0
No files found.
doc/development/api_graphql_styleguide.md
View file @
20bf7c6d
...
...
@@ -636,6 +636,37 @@ found, we should raise a
`Gitlab::Graphql::Errors::ResourceNotAvailable`
error. Which will be
correctly rendered to the clients.
## Validating arguments
For validations of single arguments, use the
[
`prepare` option
](
https://github.com/rmosolgo/graphql-ruby/blob/master/guides/fields/arguments.md
)
as normal.
Sometimes a mutation or resolver may accept a number of optional
arguments, but still want to validate that at least one of the optional
arguments were given. In this situation, consider using the
`#ready?`
method within your mutation or resolver to provide the validation. The
`#ready?`
method will be called before any work is done within the
`#resolve`
method.
Example:
```
ruby
def
ready?
(
**
args
)
if
args
.
values_at
(
:body
,
:position
).
compact
.
blank?
raise
Gitlab
::
Graphql
::
Errors
::
ArgumentError
,
'body or position arguments are required'
end
# Always remember to call `#super`
super
(
args
)
end
```
In the future this may be able to be done using
`InputUnions`
if
[
this RFC
](
https://github.com/graphql/graphql-spec/blob/master/rfcs/InputUnion.md
)
is merged.
## GitLab's custom scalars
### `Types::TimeType`
...
...
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