-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
core.ts
71 lines (64 loc) · 2.38 KB
/
core.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
65
66
67
68
69
70
71
import { IncomingMessage, ServerResponse } from 'http';
import type { GraphQLResolveInfo } from 'graphql';
import type { GqlNames } from './utils';
import type { KeystoneContext, SessionContext } from './context';
export type DatabaseProvider = 'sqlite' | 'postgresql' | 'mongodb';
export type CreateRequestContext = (
req: IncomingMessage,
res: ServerResponse
) => Promise<KeystoneContext>;
export type CreateContext = (args: {
sessionContext?: SessionContext<any>;
sudo?: boolean;
req?: IncomingMessage;
}) => KeystoneContext;
export type SessionImplementation = {
createSessionContext(
req: IncomingMessage,
res: ServerResponse,
createContext: CreateContext
): Promise<SessionContext<any>>;
};
export type GraphQLResolver = (
root: any,
args: any,
context: KeystoneContext,
info: GraphQLResolveInfo
) => any;
export type GraphQLSchemaExtension = {
typeDefs: string;
resolvers: Record<string, Record<string, GraphQLResolver>>;
};
// TODO: don't duplicate this between here and packages/keystone/ListTypes/list.js
export function getGqlNames({
listKey,
pluralGraphQLName,
}: {
listKey: string;
pluralGraphQLName: string;
}): GqlNames {
const lowerPluralName = pluralGraphQLName.slice(0, 1).toLowerCase() + pluralGraphQLName.slice(1);
const lowerSingularName = listKey.slice(0, 1).toLowerCase() + listKey.slice(1);
return {
outputTypeName: listKey,
itemQueryName: lowerSingularName,
listQueryName: lowerPluralName,
listQueryCountName: `${lowerPluralName}Count`,
listOrderName: `${listKey}OrderByInput`,
deleteMutationName: `delete${listKey}`,
updateMutationName: `update${listKey}`,
createMutationName: `create${listKey}`,
deleteManyMutationName: `delete${pluralGraphQLName}`,
updateManyMutationName: `update${pluralGraphQLName}`,
createManyMutationName: `create${pluralGraphQLName}`,
whereInputName: `${listKey}WhereInput`,
whereUniqueInputName: `${listKey}WhereUniqueInput`,
updateInputName: `${listKey}UpdateInput`,
createInputName: `${listKey}CreateInput`,
updateManyInputName: `${listKey}UpdateArgs`,
relateToManyForCreateInputName: `${listKey}RelateToManyForCreateInput`,
relateToManyForUpdateInputName: `${listKey}RelateToManyForUpdateInput`,
relateToOneForCreateInputName: `${listKey}RelateToOneForCreateInput`,
relateToOneForUpdateInputName: `${listKey}RelateToOneForUpdateInput`,
};
}