File tree Expand file tree Collapse file tree 6 files changed +63
-2
lines changed Expand file tree Collapse file tree 6 files changed +63
-2
lines changed Original file line number Diff line number Diff line change
1
+ # [ 0.20.0-beta.1] ( https://github.com/cloudgraphdev/sdk/compare/0.19.0...0.20.0-beta.1 ) (2022-06-09)
2
+
3
+
4
+ ### Features
5
+
6
+ * Added util function to generate unique ids ([ 8d8fc11] ( https://github.com/cloudgraphdev/sdk/commit/8d8fc11e0a1678ce47ce0f32f296009de253b8da ) )
7
+ * Adding utils to generate mutations dynamically ([ c1d6fa3] ( https://github.com/cloudgraphdev/sdk/commit/c1d6fa3d2dec99bc25d9454b0c7801340650cffe ) )
8
+
9
+ # [ 0.20.0-alpha.2] ( https://github.com/cloudgraphdev/sdk/compare/0.20.0-alpha.1...0.20.0-alpha.2 ) (2022-06-09)
10
+
11
+
12
+ ### Features
13
+
14
+ * Added util function to generate unique ids ([ 8d8fc11] ( https://github.com/cloudgraphdev/sdk/commit/8d8fc11e0a1678ce47ce0f32f296009de253b8da ) )
15
+
16
+ # [ 0.20.0-alpha.1] ( https://github.com/cloudgraphdev/sdk/compare/0.19.0...0.20.0-alpha.1 ) (2022-05-11)
17
+
18
+
19
+ ### Features
20
+
21
+ * Adding utils to generate mutations dynamically ([ c1d6fa3] ( https://github.com/cloudgraphdev/sdk/commit/c1d6fa3d2dec99bc25d9454b0c7801340650cffe ) )
22
+
1
23
# [ 0.19.0] ( https://github.com/cloudgraphdev/sdk/compare/0.18.1...0.19.0 ) (2022-05-02)
2
24
3
25
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @cloudgraph/sdk" ,
3
- "version" : " 0.19.0 " ,
3
+ "version" : " 0.20.0-beta.1 " ,
4
4
"description" : " SDK for cloud graph providers and cli" ,
5
5
"main" : " dist/src/index.js" ,
6
6
"types" : " dist/src/index.d.ts" ,
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 {
@@ -36,11 +37,13 @@ import {
36
37
intersectStringArrays ,
37
38
getKeyByValue ,
38
39
toCamel ,
40
+ generateUniqueId ,
39
41
} from './utils'
40
42
import {
41
43
mergeSchemas ,
42
44
getSchemaFromFolder ,
43
45
generateSchemaMapDynamically ,
46
+ generateEntityMutations ,
44
47
} from './utils/schema'
45
48
46
49
// Export Utils
@@ -52,6 +55,8 @@ export {
52
55
mergeSchemas ,
53
56
getSchemaFromFolder ,
54
57
generateSchemaMapDynamically ,
58
+ generateEntityMutations ,
59
+ generateUniqueId ,
55
60
}
56
61
57
62
export { PluginModule , PluginType , Result , pluginMap }
@@ -69,6 +74,7 @@ export type {
69
74
JsRule ,
70
75
JsonRule ,
71
76
Entity ,
77
+ EntityMutations ,
72
78
StorageEngineConnectionConfig ,
73
79
StorageEngineConfig ,
74
80
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
1
+ import crypto from 'crypto'
1
2
import camelCase from 'lodash/camelCase'
2
3
3
4
export const toCamel = ( o : any ) : any => {
@@ -67,3 +68,11 @@ export const sortResourcesDependencies = (
67
68
}
68
69
return 0
69
70
} )
71
+
72
+ /**
73
+ * Create an unique hash identifier
74
+ * @param entity entire entity to create identifier
75
+ * @returns unique identifier
76
+ */
77
+ export const generateUniqueId = ( entity : any ) : string =>
78
+ crypto . createHash ( 'md5' ) . update ( JSON . stringify ( entity ) ) . digest ( 'hex' )
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