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
b7e39285
Commit
b7e39285
authored
Jun 09, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set author as nullable in snippet GraphQL Type
parent
a663b754
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
10 deletions
+52
-10
app/graphql/types/snippet_type.rb
app/graphql/types/snippet_type.rb
+4
-1
changelogs/unreleased/fj-change-snippet-author-nullable-graphql-type.yml
...leased/fj-change-snippet-author-nullable-graphql-type.yml
+5
-0
doc/api/graphql/reference/gitlab_schema.graphql
doc/api/graphql/reference/gitlab_schema.graphql
+1
-1
doc/api/graphql/reference/gitlab_schema.json
doc/api/graphql/reference/gitlab_schema.json
+3
-7
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-1
spec/graphql/types/snippet_type_spec.rb
spec/graphql/types/snippet_type_spec.rb
+38
-0
No files found.
app/graphql/types/snippet_type.rb
View file @
b7e39285
...
...
@@ -27,9 +27,12 @@ module Types
authorize: :read_project
,
resolve:
->
(
snippet
,
args
,
context
)
{
Gitlab
::
Graphql
::
Loaders
::
BatchModelLoader
.
new
(
Project
,
snippet
.
project_id
).
find
}
# Author can be nil in some scenarios. For example,
# when the admin setting restricted visibility
# level is set to public
field
:author
,
Types
::
UserType
,
description:
'The owner of the snippet'
,
null:
fals
e
,
null:
tru
e
,
resolve:
->
(
snippet
,
args
,
context
)
{
Gitlab
::
Graphql
::
Loaders
::
BatchModelLoader
.
new
(
User
,
snippet
.
author_id
).
find
}
field
:file_name
,
GraphQL
::
STRING_TYPE
,
...
...
changelogs/unreleased/fj-change-snippet-author-nullable-graphql-type.yml
0 → 100644
View file @
b7e39285
---
title
:
Set author as
null
able in snippet GraphQL Type
merge_request
:
34135
author
:
type
:
fixed
doc/api/graphql/reference/gitlab_schema.graphql
View file @
b7e39285
...
...
@@ -11155,7 +11155,7 @@ type Snippet implements Noteable {
"""
The
owner
of
the
snippet
"""
author
:
User
!
author
:
User
"""
Snippet
blob
...
...
doc/api/graphql/reference/gitlab_schema.json
View file @
b7e39285
...
...
@@ -32945,13 +32945,9 @@
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "User",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
doc/api/graphql/reference/index.md
View file @
b7e39285
...
...
@@ -1630,7 +1630,7 @@ Represents a snippet entry
| Name | Type | Description |
| --- | ---- | ---------- |
|
`author`
| User
!
| The owner of the snippet |
|
`author`
| User | The owner of the snippet |
|
`blob`
| SnippetBlob! | Snippet blob |
|
`createdAt`
| Time! | Timestamp this snippet was created |
|
`description`
| String | Description of the snippet |
...
...
spec/graphql/types/snippet_type_spec.rb
View file @
b7e39285
...
...
@@ -16,6 +16,44 @@ describe GitlabSchema.types['Snippet'] do
expect
(
described_class
).
to
have_graphql_fields
(
*
expected_fields
)
end
context
'when restricted visibility level is set to public'
do
let_it_be
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
,
:public
,
author:
user
)
}
let
(
:current_user
)
{
user
}
let
(
:query
)
do
%(
{
snippets {
nodes {
author {
id
}
}
}
}
)
end
let
(
:response
)
{
subject
.
dig
(
'data'
,
'snippets'
,
'nodes'
)[
0
]
}
subject
{
GitlabSchema
.
execute
(
query
,
context:
{
current_user:
current_user
}).
as_json
}
before
do
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
PUBLIC
])
end
it
'returns snippet author'
do
expect
(
response
[
'author'
]).
to
be_present
end
context
'when user is not logged in'
do
let
(
:current_user
)
{
nil
}
it
'returns snippet author as nil'
do
expect
(
response
[
'author'
]).
to
be_nil
end
end
end
describe
'authorizations'
do
specify
{
expect
(
described_class
).
to
require_graphql_authorizations
(
:read_snippet
)
}
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