forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtarget-resource.js
More file actions
84 lines (83 loc) · 2.9 KB
/
Copy pathtarget-resource.js
File metadata and controls
84 lines (83 loc) · 2.9 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { GraphQLObjectType, GraphQLString, GraphQLList } from 'graphql'
import { globalIdField } from 'graphql-relay'
import { ResourceTypeEnums } from '../../enums/resource-type'
export const targetResourceType = new GraphQLObjectType({
name: 'TargetResource',
description: 'Resource that was the target of a specified action by a user.',
fields: () => ({
resource: {
type: GraphQLString,
description: 'Name of the targeted resource.',
resolve: async ({ resource, resourceType }, _, { language }) => {
if (resourceType === 'organization') {
return resource[`${language}`]
}
return resource
},
},
organization: {
type: new GraphQLObjectType({
name: 'TargetOrganization',
description: 'Organization that the resource is affiliated with.',
fields: () => ({
id: globalIdField('organization'),
name: {
type: GraphQLString,
description: 'Name of the affiliated organization.',
resolve: async ({ id, name }, _, { loaders: { loadOrgByKey } }) => {
const org = await loadOrgByKey.load(id)
if (typeof org === 'undefined') {
return name
}
return org.name
},
},
}),
}),
description: 'Organization that the resource is affiliated with.',
resolve: ({ organization }) => organization,
},
resourceType: {
type: ResourceTypeEnums,
description: 'Type of resource that was modified: user, domain, or organization.',
resolve: ({ resourceType }) => resourceType,
},
updatedProperties: {
type: new GraphQLList(
new GraphQLObjectType({
name: 'UpdatedProperties',
description: 'Object describing how a resource property was updated.',
fields: () => ({
name: {
type: GraphQLString,
description: 'Name of updated resource.',
resolve: ({ name }) => name,
},
oldValue: {
type: GraphQLString,
description: 'Old value of updated property.',
resolve: ({ name, oldValue }) => {
if (name === 'selectors' || name === 'tags') {
return JSON.stringify(oldValue)
}
return oldValue
},
},
newValue: {
type: GraphQLString,
description: 'New value of updated property.',
resolve: ({ name, newValue }) => {
if (name === 'selectors' || name === 'tags') {
return JSON.stringify(newValue)
}
return newValue
},
},
}),
}),
),
description: 'List of resource properties that were modified.',
resolve: ({ updatedProperties }) => updatedProperties,
},
}),
})