File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import {
14
14
ServiceConnection ,
15
15
ProviderData ,
16
16
Entity ,
17
+ EntityMutations ,
17
18
SchemaMap ,
18
19
} from './types'
19
20
import {
@@ -41,6 +42,7 @@ import {
41
42
mergeSchemas ,
42
43
getSchemaFromFolder ,
43
44
generateSchemaMapDynamically ,
45
+ generateEntityMutations ,
44
46
} from './utils/schema'
45
47
46
48
// Export Utils
@@ -52,6 +54,7 @@ export {
52
54
mergeSchemas ,
53
55
getSchemaFromFolder ,
54
56
generateSchemaMapDynamically ,
57
+ generateEntityMutations ,
55
58
}
56
59
57
60
export { PluginModule , PluginType , Result , pluginMap }
@@ -69,6 +72,7 @@ export type {
69
72
JsRule ,
70
73
JsonRule ,
71
74
Entity ,
75
+ EntityMutations ,
72
76
StorageEngineConnectionConfig ,
73
77
StorageEngineConfig ,
74
78
StorageEngine ,
Original file line number Diff line number Diff line change @@ -49,10 +49,17 @@ export interface Service {
49
49
rawData : any
50
50
} ) => any
51
51
}
52
+
53
+ export interface EntityMutations {
54
+ query ?: string
55
+ upsert : string
56
+ delete : string
57
+ }
58
+
52
59
export interface Entity {
53
60
className ?: string
54
61
name : string
55
- mutation : string
62
+ mutation : EntityMutations | string
56
63
data : any [ ] | any
57
64
}
58
65
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { loadFilesSync } from '@graphql-tools/load-files'
3
3
import { print } from 'graphql'
4
4
import path from 'path'
5
5
6
+ import { EntityMutations } from '../types'
7
+
6
8
export const mergeSchemas = ( currSchema : string , additions : string [ ] ) => {
7
9
const s = mergeTypeDefs ( [ currSchema , ...additions ] )
8
10
return print ( s )
@@ -36,3 +38,18 @@ export const generateSchemaMapDynamically = (
36
38
}
37
39
return resourceTypeNamesToFieldsMap
38
40
}
41
+
42
+ const generateDeleteMutation = ( schemaName : string ) : string =>
43
+ `mutation delete${ schemaName } ($input: [String!]!){delete${ schemaName } (filter: { id: { in: $input }}) { numUids } }`
44
+
45
+ const generateUpsertMutation = ( schemaName : string ) : string =>
46
+ `mutation($input: [Add${ schemaName } Input!]!) { add${ schemaName } (input: $input, upsert: true) { numUids } }`
47
+
48
+ export const generateEntityMutations = (
49
+ schemaName : string
50
+ ) : EntityMutations => {
51
+ return {
52
+ upsert : generateUpsertMutation ( schemaName ) ,
53
+ delete : generateDeleteMutation ( schemaName ) ,
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments