Commit 7f57e2e3 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'fj-change-snippet-author-nullable-graphql-type' into 'master'

Set author as nullable in snippet GraphQL Type

See merge request gitlab-org/gitlab!34135
parents f821c46b 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: false,
null: true,
resolve: -> (snippet, args, context) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, snippet.author_id).find }
field :file_name, GraphQL::STRING_TYPE,
......
---
title: Set author as nullable in snippet GraphQL Type
merge_request: 34135
author:
type: fixed
......@@ -11240,7 +11240,7 @@ type Snippet implements Noteable {
"""
The owner of the snippet
"""
author: User!
author: User
"""
Snippet blob
......
......@@ -33183,13 +33183,9 @@
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "User",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
......@@ -1641,7 +1641,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 |
| `blobs` | SnippetBlob! => Array | Snippet blobs |
| `createdAt` | Time! | Timestamp this snippet was created |
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment