-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathUserConnection.ts
More file actions
36 lines (33 loc) · 933 Bytes
/
Copy pathUserConnection.ts
File metadata and controls
36 lines (33 loc) · 933 Bytes
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
import { GqlInfo, Int } from "grats";
import * as DB from "../Database.js";
import { VC } from "../ViewerContext.js";
import { User } from "./User.js";
import { Connection } from "../graphql/Connection.js";
import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js";
/**
* Convenience field to get the nodes from a connection.
* @gqlField */
export function nodes(userConnection: Connection<User>): User[] {
return userConnection.edges.map((edge) => edge.node);
}
// --- Root Fields ---
/**
* All users in the system. Note that there is no guarantee of order.
* @gqlQueryField */
export async function users(
args: {
first?: Int | null;
after?: string | null;
last?: Int | null;
before?: string | null;
},
vc: VC,
info: GqlInfo,
): Promise<Connection<User>> {
return connectionFromSelectOrCount(
() => DB.selectUsers(vc),
() => DB.selectUsersCount(vc),
args,
info,
);
}