Skip to content

Commit 3dacec7

Browse files
authored
Merge pull request #190 from marmelab/support-delete-and-remove
Add support for deleteXXX in addition to removeXXX
2 parents 65bb0d1 + 7a43bf2 commit 3dacec7

File tree

5 files changed

+26
-4
lines changed

5 files changed

+26
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ type Mutation {
119119
createPost(data: String): Post
120120
createManyPost(data: [{data:String}]): [Post]
121121
updatePost(data: String): Post
122-
removePost(id: ID!): Post
122+
deletePost(id: ID!): Post
123123
}
124124
type Post {
125125
id: ID!

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "json-graphql-server",
3-
"version": "3.1.2",
3+
"version": "3.2.0",
44
"type": "module",
55
"main": "./dist/json-graphql-server.cjs",
66
"module": "./dist/json-graphql-server.js",
@@ -72,5 +72,6 @@
7272
},
7373
"bin": {
7474
"json-graphql-server": "bin/json-graphql-server.cjs"
75-
}
76-
}
75+
},
76+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
77+
}

src/introspection/getSchemaFromData.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ export default (data) => {
179179
id: { type: new GraphQLNonNull(GraphQLID) },
180180
},
181181
};
182+
fields[`delete${type.name}`] = {
183+
type: typesByName[type.name],
184+
args: {
185+
id: { type: new GraphQLNonNull(GraphQLID) },
186+
},
187+
};
182188
return fields;
183189
}, {}),
184190
});

src/introspection/getSchemaFromData.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ test('creates three mutation fields per data type', () => {
211211
type: new GraphQLNonNull(GraphQLID),
212212
}),
213213
]);
214+
expect(mutations['deletePost'].type.name).toEqual(PostType.name);
215+
expect(mutations['deletePost'].args).toEqual([
216+
expect.objectContaining({
217+
name: 'id',
218+
type: new GraphQLNonNull(GraphQLID),
219+
}),
220+
]);
214221
expect(mutations['createUser'].type.name).toEqual(UserType.name);
215222
expect(mutations['createUser'].args).toEqual([
216223
expect.objectContaining({
@@ -236,6 +243,13 @@ test('creates three mutation fields per data type', () => {
236243
type: new GraphQLNonNull(GraphQLID),
237244
}),
238245
]);
246+
expect(mutations['deleteUser'].type.name).toEqual(UserType.name);
247+
expect(mutations['deleteUser'].args).toEqual([
248+
expect.objectContaining({
249+
name: 'id',
250+
type: new GraphQLNonNull(GraphQLID),
251+
}),
252+
]);
239253
});
240254

241255
test('creates the mutation *Input type for createMany', () => {

src/resolver/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const getMutationResolvers = (entityName, data) => ({
2424
[`createMany${entityName}`]: createMany(data),
2525
[`update${entityName}`]: update(data),
2626
[`remove${entityName}`]: remove(data),
27+
[`delete${entityName}`]: remove(data),
2728
});
2829

2930
export default (data) => {

0 commit comments

Comments
 (0)