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+
123# [ 0.19.0] ( https://github.com/cloudgraphdev/sdk/compare/0.18.1...0.19.0 ) (2022-05-02)
224
325
Original file line number Diff line number Diff line change 11{
22 "name" : " @cloudgraph/sdk" ,
3- "version" : " 0.19.0 " ,
3+ "version" : " 0.20.0-beta.1 " ,
44 "description" : " SDK for cloud graph providers and cli" ,
55 "main" : " dist/src/index.js" ,
66 "types" : " dist/src/index.d.ts" ,
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 {
@@ -36,11 +37,13 @@ import {
3637 intersectStringArrays ,
3738 getKeyByValue ,
3839 toCamel ,
40+ generateUniqueId ,
3941} from './utils'
4042import {
4143 mergeSchemas ,
4244 getSchemaFromFolder ,
4345 generateSchemaMapDynamically ,
46+ generateEntityMutations ,
4447} from './utils/schema'
4548
4649// Export Utils
@@ -52,6 +55,8 @@ export {
5255 mergeSchemas ,
5356 getSchemaFromFolder ,
5457 generateSchemaMapDynamically ,
58+ generateEntityMutations ,
59+ generateUniqueId ,
5560}
5661
5762export { PluginModule , PluginType , Result , pluginMap }
@@ -69,6 +74,7 @@ export type {
6974 JsRule ,
7075 JsonRule ,
7176 Entity ,
77+ EntityMutations ,
7278 StorageEngineConnectionConfig ,
7379 StorageEngineConfig ,
7480 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 1+ import crypto from 'crypto'
12import camelCase from 'lodash/camelCase'
23
34export const toCamel = ( o : any ) : any => {
@@ -67,3 +68,11 @@ export const sortResourcesDependencies = (
6768 }
6869 return 0
6970 } )
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'
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