-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Implementation.js
59 lines (53 loc) · 1.56 KB
/
Implementation.js
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
import { Implementation } from '../../Implementation';
import { MongooseFieldAdapter } from '@keystonejs/adapter-mongoose';
import { KnexFieldAdapter } from '@keystonejs/adapter-knex';
import { parseFieldAccess } from '@keystonejs/access-control';
export class Virtual extends Implementation {
constructor() {
super(...arguments);
}
gqlOutputFields() {
return [`${this.path}: ${this.config.graphQLReturnType || `String`}`];
}
getGqlAuxTypes() {
return this.config.extendGraphQLTypes || [];
}
gqlOutputFieldResolvers() {
return { [`${this.path}`]: this.config.resolver };
}
gqlQueryInputFields() {
return [];
}
extendAdminMeta(meta) {
return {
...meta,
isOrderable: false,
graphQLSelection: this.config.graphQLReturnFragment || '',
isReadOnly: true,
};
}
parseFieldAccess(args) {
const parsedAccess = parseFieldAccess(args);
const fieldDefaults = { create: false, update: false, delete: false };
return Object.keys(parsedAccess).reduce((prev, schemaName) => {
prev[schemaName] = { ...fieldDefaults, read: parsedAccess[schemaName].read };
return prev;
}, {});
}
}
const CommonTextInterface = superclass =>
class extends superclass {
getQueryConditions() {
return {};
}
};
export class MongoVirtualInterface extends CommonTextInterface(MongooseFieldAdapter) {
addToMongooseSchema() {}
}
export class KnexVirtualInterface extends CommonTextInterface(KnexFieldAdapter) {
constructor() {
super(...arguments);
this.realKeys = [];
}
addToTableSchema() {}
}