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 {
1414 ServiceConnection ,
1515 ProviderData ,
1616 Entity ,
17+ EntityMutations ,
1718 SchemaMap ,
1819} from './types'
1920import {
@@ -41,6 +42,7 @@ import {
4142 mergeSchemas ,
4243 getSchemaFromFolder ,
4344 generateSchemaMapDynamically ,
45+ generateEntityMutations ,
4446} from './utils/schema'
4547
4648// Export Utils
@@ -52,6 +54,7 @@ export {
5254 mergeSchemas ,
5355 getSchemaFromFolder ,
5456 generateSchemaMapDynamically ,
57+ generateEntityMutations ,
5558}
5659
5760export { PluginModule , PluginType , Result , pluginMap }
@@ -69,6 +72,7 @@ export type {
6972 JsRule ,
7073 JsonRule ,
7174 Entity ,
75+ EntityMutations ,
7276 StorageEngineConnectionConfig ,
7377 StorageEngineConfig ,
7478 StorageEngine ,
Original file line number Diff line number Diff line change @@ -49,10 +49,17 @@ export interface Service {
4949 rawData : any
5050 } ) => any
5151}
52+
53+ export interface EntityMutations {
54+ query ?: string
55+ upsert : string
56+ delete : string
57+ }
58+
5259export interface Entity {
5360 className ?: string
5461 name : string
55- mutation : string
62+ mutation : EntityMutations | string
5663 data : any [ ] | any
5764}
5865
Original file line number Diff line number Diff line change @@ -3,6 +3,8 @@ import { loadFilesSync } from '@graphql-tools/load-files'
33import { print } from 'graphql'
44import path from 'path'
55
6+ import { EntityMutations } from '../types'
7+
68export const mergeSchemas = ( currSchema : string , additions : string [ ] ) => {
79 const s = mergeTypeDefs ( [ currSchema , ...additions ] )
810 return print ( s )
@@ -36,3 +38,18 @@ export const generateSchemaMapDynamically = (
3638 }
3739 return resourceTypeNamesToFieldsMap
3840}
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