-
Notifications
You must be signed in to change notification settings - Fork 6
/
GraphQLClient.ts
64 lines (61 loc) · 1.62 KB
/
GraphQLClient.ts
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
import {
GraphQLID,
GraphQLList,
GraphQLNonNull,
GraphQLString,
GraphQLBoolean,
GraphQLObjectType
} from "graphql";
import {
connectionFromArray,
connectionArgs,
ConnectionArguments
} from "graphql-relay";
import { Client } from "../model";
import { Context } from "../Context";
import { GraphQLUserConnection } from "./GraphQLUserConnection";
import { filter } from "../util/filter";
export const GraphQLClient = new GraphQLObjectType<Client, Context>({
name: "Client",
interfaces: () => [],
fields: () => ({
id: { type: new GraphQLNonNull(GraphQLID) },
enabled: {
type: new GraphQLNonNull(GraphQLBoolean)
},
name: { type: GraphQLString },
description: { type: GraphQLString },
secrets: {
type: new GraphQLList(GraphQLString),
async resolve(
client,
args,
{ realm, authorization: a, tx }: Context
): Promise<null | string[]> {
return a && (await client.isAccessibleBy(realm, a, tx, "read.secrets"))
? [...client.secrets]
: null;
}
},
urls: { type: new GraphQLList(GraphQLString) },
users: {
type: GraphQLUserConnection,
args: connectionArgs,
async resolve(
client,
args: ConnectionArguments,
{ realm, authorization: a, tx }: Context
) {
return a &&
(await client.isAccessibleBy(realm, a, tx, "read.assignments"))
? connectionFromArray(
await filter(await client.users(tx), user =>
user.isAccessibleBy(realm, a, tx)
),
args
)
: null;
}
}
})
});