-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathaffiliation.js
More file actions
42 lines (40 loc) · 1.41 KB
/
affiliation.js
File metadata and controls
42 lines (40 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {GraphQLObjectType} from 'graphql'
import {globalIdField} from 'graphql-relay'
import {RoleEnums} from '../../enums'
import {organizationType} from '../../organization/objects'
import {userSharedType} from '../../user/objects'
import {nodeInterface} from '../../node'
export const affiliationType = new GraphQLObjectType({
name: 'Affiliation',
fields: () => ({
id: globalIdField('affiliation'),
permission: {
type: RoleEnums,
description: "User's level of access to a given organization.",
resolve: ({permission}) => permission,
},
user: {
type: userSharedType,
description: 'The affiliated users information.',
resolve: async ({_to}, _args, {loaders: {loadUserByKey}}) => {
const userKey = _to.split('/')[1]
const user = await loadUserByKey.load(userKey)
user.id = user._key
return user
},
},
organization: {
type: organizationType,
description: 'The affiliated organizations information.',
resolve: async ({_from}, _args, {loaders: {loadOrgByKey}}) => {
const orgKey = _from.split('/')[1]
const org = await loadOrgByKey.load(orgKey)
org.id = org._key
return org
},
},
}),
interfaces: [nodeInterface],
description:
'User Affiliations containing the permission level for the given organization, the users information, and the organizations information.',
})