diff --git a/README.md b/README.md index 8e230c8..2bf1fff 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,7 @@ type Mutation { createPost(data: String): Post createManyPost(data: [{data:String}]): [Post] updatePost(data: String): Post - removePost(id: ID!): Post + deletePost(id: ID!): Post } type Post { id: ID! diff --git a/package.json b/package.json index 0df77b4..16679d5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "json-graphql-server", - "version": "3.1.2", + "version": "3.2.0", "type": "module", "main": "./dist/json-graphql-server.cjs", "module": "./dist/json-graphql-server.js", @@ -72,5 +72,6 @@ }, "bin": { "json-graphql-server": "bin/json-graphql-server.cjs" - } -} \ No newline at end of file + }, + "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" +} diff --git a/src/introspection/getSchemaFromData.js b/src/introspection/getSchemaFromData.js index b4777dc..ce27edb 100644 --- a/src/introspection/getSchemaFromData.js +++ b/src/introspection/getSchemaFromData.js @@ -179,6 +179,12 @@ export default (data) => { id: { type: new GraphQLNonNull(GraphQLID) }, }, }; + fields[`delete${type.name}`] = { + type: typesByName[type.name], + args: { + id: { type: new GraphQLNonNull(GraphQLID) }, + }, + }; return fields; }, {}), }); diff --git a/src/introspection/getSchemaFromData.spec.js b/src/introspection/getSchemaFromData.spec.js index ed04ddb..a16726f 100644 --- a/src/introspection/getSchemaFromData.spec.js +++ b/src/introspection/getSchemaFromData.spec.js @@ -211,6 +211,13 @@ test('creates three mutation fields per data type', () => { type: new GraphQLNonNull(GraphQLID), }), ]); + expect(mutations['deletePost'].type.name).toEqual(PostType.name); + expect(mutations['deletePost'].args).toEqual([ + expect.objectContaining({ + name: 'id', + type: new GraphQLNonNull(GraphQLID), + }), + ]); expect(mutations['createUser'].type.name).toEqual(UserType.name); expect(mutations['createUser'].args).toEqual([ expect.objectContaining({ @@ -236,6 +243,13 @@ test('creates three mutation fields per data type', () => { type: new GraphQLNonNull(GraphQLID), }), ]); + expect(mutations['deleteUser'].type.name).toEqual(UserType.name); + expect(mutations['deleteUser'].args).toEqual([ + expect.objectContaining({ + name: 'id', + type: new GraphQLNonNull(GraphQLID), + }), + ]); }); test('creates the mutation *Input type for createMany', () => { diff --git a/src/resolver/index.js b/src/resolver/index.js index 326bc10..6ce8004 100644 --- a/src/resolver/index.js +++ b/src/resolver/index.js @@ -24,6 +24,7 @@ const getMutationResolvers = (entityName, data) => ({ [`createMany${entityName}`]: createMany(data), [`update${entityName}`]: update(data), [`remove${entityName}`]: remove(data), + [`delete${entityName}`]: remove(data), }); export default (data) => {