Commit ada36d20 authored by Jarka Košanová's avatar Jarka Košanová

Merge branch '215658-graphql-memberships' into 'master'

Add connections between User and Group or Project

See merge request gitlab-org/gitlab!33049
parents 5a589a07 4eedc07f
# frozen_string_literal: true
module Types
class AccessLevelEnum < BaseEnum
graphql_name 'AccessLevelEnum'
description 'Access level to a resource'
value 'NO_ACCESS', value: Gitlab::Access::NO_ACCESS
value 'GUEST', value: Gitlab::Access::GUEST
value 'REPORTER', value: Gitlab::Access::REPORTER
value 'DEVELOPER', value: Gitlab::Access::DEVELOPER
value 'MAINTAINER', value: Gitlab::Access::MAINTAINER
value 'OWNER', value: Gitlab::Access::OWNER
end
end
# frozen_string_literal: true
# rubocop:disable Graphql/AuthorizeTypes
module Types
class AccessLevelType < Types::BaseObject
graphql_name 'AccessLevel'
description 'Represents the access level of a relationship between a User and object that it is related to'
field :integer_value, GraphQL::INT_TYPE, null: true,
description: 'Integer representation of access level',
method: :to_i
field :string_value, Types::AccessLevelEnum, null: true,
description: 'String representation of access level',
method: :to_i
end
end
# frozen_string_literal: true
module Types
class GroupMemberType < BaseObject
expose_permissions Types::PermissionTypes::Group
authorize :read_group
implements MemberInterface
graphql_name 'GroupMember'
description 'Represents a Group Member'
field :group, Types::GroupType, null: true,
description: 'Group that a User is a member of',
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Group, obj.source_id).find }
end
end
# frozen_string_literal: true
module Types
module MemberInterface
include BaseInterface
field :access_level, Types::AccessLevelType, null: true,
description: 'GitLab::Access level'
field :created_by, Types::UserType, null: true,
description: 'User that authorized membership'
field :created_at, Types::TimeType, null: true,
description: 'Date and time the membership was created'
field :updated_at, Types::TimeType, null: true,
description: 'Date and time the membership was last updated'
field :expires_at, Types::TimeType, null: true,
description: 'Date and time the membership expires'
end
end
......@@ -3,18 +3,23 @@
module Types
class ProjectMemberType < BaseObject
graphql_name 'ProjectMember'
description 'Member of a project'
description 'Represents a Project Member'
expose_permissions Types::PermissionTypes::Project
implements MemberInterface
authorize :read_project
field :id, GraphQL::ID_TYPE, null: false,
description: 'ID of the member'
field :access_level, GraphQL::INT_TYPE, null: false,
description: 'Access level of the member'
field :user, Types::UserType, null: false,
description: 'User that is associated with the member object',
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(User, obj.user_id).find }
field :project, Types::ProjectType, null: true,
description: 'Project that User is a member of',
resolve: -> (obj, _args, _ctx) { Gitlab::Graphql::Loaders::BatchModelLoader.new(Project, obj.source_id).find }
end
end
......@@ -25,6 +25,12 @@ module Types
field :todos, Types::TodoType.connection_type, null: false,
resolver: Resolvers::TodoResolver,
description: 'Todos of the user'
field :group_memberships, Types::GroupMemberType.connection_type, null: true,
description: 'Group memberships of the user',
method: :group_members
field :project_memberships, Types::ProjectMemberType.connection_type, null: true,
description: 'Project memberships of the user',
method: :project_members
# Merge request field: MRs can be either authored or assigned:
field :authored_merge_requests, Types::MergeRequestType.connection_type, null: true,
......
---
title: Adds groupMembership and projectMembership to GraphQL API
merge_request: 33049
author:
type: added
"""
Represents the access level of a relationship between a User and object that it is related to
"""
type AccessLevel {
"""
Integer representation of access level
"""
integerValue: Int
"""
String representation of access level
"""
stringValue: AccessLevelEnum
}
"""
Access level to a resource
"""
enum AccessLevelEnum {
DEVELOPER
GUEST
MAINTAINER
NO_ACCESS
OWNER
REPORTER
}
"""
Autogenerated input type of AddAwardEmoji
"""
......@@ -5012,6 +5039,81 @@ type Group {
webUrl: String!
}
"""
Represents a Group Member
"""
type GroupMember implements MemberInterface {
"""
GitLab::Access level
"""
accessLevel: AccessLevel
"""
Date and time the membership was created
"""
createdAt: Time
"""
User that authorized membership
"""
createdBy: User
"""
Date and time the membership expires
"""
expiresAt: Time
"""
Group that a User is a member of
"""
group: Group
"""
Date and time the membership was last updated
"""
updatedAt: Time
"""
Permissions for the current user on the resource
"""
userPermissions: GroupPermissions!
}
"""
The connection type for GroupMember.
"""
type GroupMemberConnection {
"""
A list of edges.
"""
edges: [GroupMemberEdge]
"""
A list of nodes.
"""
nodes: [GroupMember]
"""
Information to aid in pagination.
"""
pageInfo: PageInfo!
}
"""
An edge in a connection.
"""
type GroupMemberEdge {
"""
A cursor for use in pagination.
"""
cursor: String!
"""
The item at the end of the edge.
"""
node: GroupMember
}
type GroupPermissions {
"""
Indicates the user can perform `read_group` on this resource
......@@ -6200,6 +6302,33 @@ type MarkAsSpamSnippetPayload {
snippet: Snippet
}
interface MemberInterface {
"""
GitLab::Access level
"""
accessLevel: AccessLevel
"""
Date and time the membership was created
"""
createdAt: Time
"""
User that authorized membership
"""
createdBy: User
"""
Date and time the membership expires
"""
expiresAt: Time
"""
Date and time the membership was last updated
"""
updatedAt: Time
}
type MergeRequest implements Noteable {
"""
Indicates if members of the target project can push to the fork
......@@ -9156,23 +9285,53 @@ type ProjectEdge {
}
"""
Member of a project
Represents a Project Member
"""
type ProjectMember {
type ProjectMember implements MemberInterface {
"""
GitLab::Access level
"""
accessLevel: AccessLevel
"""
Date and time the membership was created
"""
createdAt: Time
"""
User that authorized membership
"""
createdBy: User
"""
Access level of the member
Date and time the membership expires
"""
accessLevel: Int!
expiresAt: Time
"""
ID of the member
"""
id: ID!
"""
Project that User is a member of
"""
project: Project
"""
Date and time the membership was last updated
"""
updatedAt: Time
"""
User that is associated with the member object
"""
user: User!
"""
Permissions for the current user on the resource
"""
userPermissions: ProjectPermissions!
}
"""
......@@ -12626,6 +12785,31 @@ type User {
"""
avatarUrl: String
"""
Group memberships of the user
"""
groupMemberships(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): GroupMemberConnection
"""
ID of the user
"""
......@@ -12636,6 +12820,31 @@ type User {
"""
name: String!
"""
Project memberships of the user
"""
projectMemberships(
"""
Returns the elements in the list that come after the specified cursor.
"""
after: String
"""
Returns the elements in the list that come before the specified cursor.
"""
before: String
"""
Returns the first _n_ elements from the list.
"""
first: Int
"""
Returns the last _n_ elements from the list.
"""
last: Int
): ProjectMemberConnection
"""
Snippets authored by the user
"""
......
......@@ -9,6 +9,94 @@
},
"subscriptionType": null,
"types": [
{
"kind": "OBJECT",
"name": "AccessLevel",
"description": "Represents the access level of a relationship between a User and object that it is related to",
"fields": [
{
"name": "integerValue",
"description": "Integer representation of access level",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "stringValue",
"description": "String representation of access level",
"args": [
],
"type": {
"kind": "ENUM",
"name": "AccessLevelEnum",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "ENUM",
"name": "AccessLevelEnum",
"description": "Access level to a resource",
"fields": null,
"inputFields": null,
"interfaces": null,
"enumValues": [
{
"name": "NO_ACCESS",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "GUEST",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "REPORTER",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "DEVELOPER",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "MAINTAINER",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "OWNER",
"description": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"possibleTypes": null
},
{
"kind": "INPUT_OBJECT",
"name": "AddAwardEmojiInput",
......@@ -13722,6 +13810,237 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "GroupMember",
"description": "Represents a Group Member",
"fields": [
{
"name": "accessLevel",
"description": "GitLab::Access level",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "AccessLevel",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdAt",
"description": "Date and time the membership was created",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdBy",
"description": "User that authorized membership",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "User",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "expiresAt",
"description": "Date and time the membership expires",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "group",
"description": "Group that a User is a member of",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "Group",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updatedAt",
"description": "Date and time the membership was last updated",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "userPermissions",
"description": "Permissions for the current user on the resource",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "GroupPermissions",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
{
"kind": "INTERFACE",
"name": "MemberInterface",
"ofType": null
}
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "GroupMemberConnection",
"description": "The connection type for GroupMember.",
"fields": [
{
"name": "edges",
"description": "A list of edges.",
"args": [
],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "GroupMemberEdge",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "nodes",
"description": "A list of nodes.",
"args": [
],
"type": {
"kind": "LIST",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "GroupMember",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "pageInfo",
"description": "Information to aid in pagination.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "PageInfo",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "GroupMemberEdge",
"description": "An edge in a connection.",
"fields": [
{
"name": "cursor",
"description": "A cursor for use in pagination.",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "String",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "node",
"description": "The item at the end of the edge.",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "GroupMember",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "GroupPermissions",
......@@ -17194,6 +17513,98 @@
"enumValues": null,
"possibleTypes": null
},
{
"kind": "INTERFACE",
"name": "MemberInterface",
"description": null,
"fields": [
{
"name": "accessLevel",
"description": "GitLab::Access level",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "AccessLevel",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdAt",
"description": "Date and time the membership was created",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdBy",
"description": "User that authorized membership",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "User",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "expiresAt",
"description": "Date and time the membership expires",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updatedAt",
"description": "Date and time the membership was last updated",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": null,
"enumValues": null,
"possibleTypes": [
{
"kind": "OBJECT",
"name": "GroupMember",
"ofType": null
},
{
"kind": "OBJECT",
"name": "ProjectMember",
"ofType": null
}
]
},
{
"kind": "OBJECT",
"name": "MergeRequest",
......@@ -26800,22 +27211,60 @@
{
"kind": "OBJECT",
"name": "ProjectMember",
"description": "Member of a project",
"description": "Represents a Project Member",
"fields": [
{
"name": "accessLevel",
"description": "Access level of the member",
"description": "GitLab::Access level",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "AccessLevel",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdAt",
"description": "Date and time the membership was created",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Int",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "createdBy",
"description": "User that authorized membership",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "User",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "expiresAt",
"description": "Date and time the membership expires",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
......@@ -26838,6 +27287,34 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "project",
"description": "Project that User is a member of",
"args": [
],
"type": {
"kind": "OBJECT",
"name": "Project",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "updatedAt",
"description": "Date and time the membership was last updated",
"args": [
],
"type": {
"kind": "SCALAR",
"name": "Time",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "user",
"description": "User that is associated with the member object",
......@@ -26855,11 +27332,33 @@
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "userPermissions",
"description": "Permissions for the current user on the resource",
"args": [
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "OBJECT",
"name": "ProjectPermissions",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [
{
"kind": "INTERFACE",
"name": "MemberInterface",
"ofType": null
}
],
"enumValues": null,
"possibleTypes": null
......@@ -37234,6 +37733,59 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "groupMemberships",
"description": "Group memberships of the user",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "GroupMemberConnection",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "id",
"description": "ID of the user",
......@@ -37270,6 +37822,59 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "projectMemberships",
"description": "Project memberships of the user",
"args": [
{
"name": "after",
"description": "Returns the elements in the list that come after the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "before",
"description": "Returns the elements in the list that come before the specified cursor.",
"type": {
"kind": "SCALAR",
"name": "String",
"ofType": null
},
"defaultValue": null
},
{
"name": "first",
"description": "Returns the first _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
},
{
"name": "last",
"description": "Returns the last _n_ elements from the list.",
"type": {
"kind": "SCALAR",
"name": "Int",
"ofType": null
},
"defaultValue": null
}
],
"type": {
"kind": "OBJECT",
"name": "ProjectMemberConnection",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "snippets",
"description": "Snippets authored by the user",
......@@ -16,6 +16,15 @@ fields and methods on a model are available via GraphQL.
CAUTION: **Caution:**
Fields that are deprecated are marked with **{warning-solid}**.
## AccessLevel
Represents the access level of a relationship between a User and object that it is related to
| Name | Type | Description |
| --- | ---- | ---------- |
| `integerValue` | Int | Integer representation of access level |
| `stringValue` | AccessLevelEnum | String representation of access level |
## AddAwardEmojiPayload
Autogenerated return type of AddAwardEmoji
......@@ -732,6 +741,20 @@ Autogenerated return type of EpicTreeReorder
| `visibility` | String | Visibility of the namespace |
| `webUrl` | String! | Web URL of the group |
## GroupMember
Represents a Group Member
| Name | Type | Description |
| --- | ---- | ---------- |
| `accessLevel` | AccessLevel | GitLab::Access level |
| `createdAt` | Time | Date and time the membership was created |
| `createdBy` | User | User that authorized membership |
| `expiresAt` | Time | Date and time the membership expires |
| `group` | Group | Group that a User is a member of |
| `updatedAt` | Time | Date and time the membership was last updated |
| `userPermissions` | GroupPermissions! | Permissions for the current user on the resource |
## GroupPermissions
| Name | Type | Description |
......@@ -1289,13 +1312,19 @@ Information about pagination in a connection.
## ProjectMember
Member of a project
Represents a Project Member
| Name | Type | Description |
| --- | ---- | ---------- |
| `accessLevel` | Int! | Access level of the member |
| `accessLevel` | AccessLevel | GitLab::Access level |
| `createdAt` | Time | Date and time the membership was created |
| `createdBy` | User | User that authorized membership |
| `expiresAt` | Time | Date and time the membership expires |
| `id` | ID! | ID of the member |
| `project` | Project | Project that User is a member of |
| `updatedAt` | Time | Date and time the membership was last updated |
| `user` | User! | User that is associated with the member object |
| `userPermissions` | ProjectPermissions! | Permissions for the current user on the resource |
## ProjectPermissions
......
# frozen_string_literal: true
require 'spec_helper'
describe GitlabSchema.types['AccessLevelEnum'] do
specify { expect(described_class.graphql_name).to eq('AccessLevelEnum') }
it 'exposes all the existing access levels' do
expect(described_class.values.keys).to match_array(%w[NO_ACCESS GUEST REPORTER DEVELOPER MAINTAINER OWNER])
end
end
# frozen_string_literal: true
require 'spec_helper'
describe GitlabSchema.types['AccessLevel'] do
specify { expect(described_class.graphql_name).to eq('AccessLevel') }
specify { expect(described_class).to require_graphql_authorizations(nil) }
it 'has expected fields' do
expected_fields = [:integer_value, :string_value]
expect(described_class).to have_graphql_fields(*expected_fields)
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Types::GroupMemberType do
specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Group) }
specify { expect(described_class.graphql_name).to eq('GroupMember') }
specify { expect(described_class).to require_graphql_authorizations(:read_group) }
it 'has the expected fields' do
expected_fields = %w[
access_level created_by created_at updated_at expires_at group
]
expect(described_class).to include_graphql_fields(*expected_fields)
end
end
......@@ -2,14 +2,18 @@
require 'spec_helper'
describe GitlabSchema.types['ProjectMember'] do
describe Types::ProjectMemberType do
specify { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Project) }
specify { expect(described_class.graphql_name).to eq('ProjectMember') }
specify { expect(described_class).to require_graphql_authorizations(:read_project) }
it 'has the expected fields' do
expected_fields = %w[id accessLevel user]
expected_fields = %w[
access_level created_by created_at updated_at expires_at project user
]
expect(described_class).to have_graphql_fields(*expected_fields)
expect(described_class).to include_graphql_fields(*expected_fields)
end
specify { expect(described_class).to require_graphql_authorizations(:read_project) }
end
......@@ -9,8 +9,19 @@ describe GitlabSchema.types['User'] do
it 'has the expected fields' do
expected_fields = %w[
id user_permissions snippets name username avatarUrl webUrl todos state
authoredMergeRequests assignedMergeRequests
id
user_permissions
snippets
name
username
avatarUrl
webUrl
todos
state
authoredMergeRequests
assignedMergeRequests
groupMemberships
projectMemberships
]
expect(described_class).to have_graphql_fields(*expected_fields)
......
# frozen_string_literal: true
require 'spec_helper'
describe 'GroupMember' do
include GraphqlHelpers
let_it_be(:member) { create(:group_member, :developer) }
let_it_be(:fields) do
<<~HEREDOC
nodes {
accessLevel {
integerValue
stringValue
}
group {
id
}
}
HEREDOC
end
let_it_be(:query) do
graphql_query_for('user', { id: member.user.to_global_id.to_s }, query_graphql_field("groupMemberships", {}, fields))
end
before do
post_graphql(query, current_user: member.user)
end
it_behaves_like 'a working graphql query'
it_behaves_like 'a working membership object query'
end
# frozen_string_literal: true
require 'spec_helper'
describe 'ProjectMember' do
include GraphqlHelpers
let_it_be(:member) { create(:project_member, :developer) }
let_it_be(:fields) do
<<~HEREDOC
nodes {
accessLevel {
integerValue
stringValue
}
project {
id
}
}
HEREDOC
end
let_it_be(:query) do
graphql_query_for('user', { id: member.user.to_global_id.to_s }, query_graphql_field("projectMemberships", {}, fields))
end
before do
post_graphql(query, current_user: member.user)
end
it_behaves_like 'a working graphql query'
it_behaves_like 'a working membership object query'
end
# frozen_string_literal: true
RSpec.shared_examples 'a working membership object query' do |model_option|
let_it_be(:member_source) { member.source }
let_it_be(:member_source_type) { member_source.class.to_s.downcase }
it 'contains edge to expected project' do
expect(
graphql_data.dig('user', "#{member_source_type}Memberships", 'nodes', 0, member_source_type, 'id')
).to eq(member.send(member_source_type).to_global_id.to_s)
end
it 'contains correct access level' do
expect(
graphql_data.dig('user', "#{member_source_type}Memberships", 'nodes', 0, 'accessLevel', 'integerValue')
).to eq(30)
expect(
graphql_data.dig('user', "#{member_source_type}Memberships", 'nodes', 0, 'accessLevel', 'stringValue')
).to eq('DEVELOPER')
end
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