Skip to content

Commit 2d7d7d8

Browse files
committedFeb 17, 2025··
Merge branch 'master' into modernize
2 parents 37b4d33 + 3dacec7 commit 2d7d7d8

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed
 

‎README.md

+1-1
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

+1-1
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",

‎src/introspection/getSchemaFromData.spec.ts

+31-13
Original file line numberDiff line numberDiff line change
@@ -107,28 +107,28 @@ const QueryType = new GraphQLObjectType({
107107

108108
test('creates one type per data type', () => {
109109
const typeMap = getSchemaFromData(
110-
data,
110+
data
111111
).getTypeMap() as ObjMap<GraphQLObjectType>;
112112
expect(typeMap.Post.name).toEqual(PostType.name);
113113
expect(Object.keys(typeMap.Post.getFields())).toEqual(
114-
Object.keys(PostType.getFields()),
114+
Object.keys(PostType.getFields())
115115
);
116116
expect(typeMap.User.name).toEqual(UserType.name);
117117
expect(Object.keys(typeMap.User.getFields())).toEqual(
118-
Object.keys(UserType.getFields()),
118+
Object.keys(UserType.getFields())
119119
);
120120
});
121121

122122
test('creates one field per relationship', () => {
123123
const typeMap = getSchemaFromData(
124-
data,
124+
data
125125
).getTypeMap() as ObjMap<GraphQLObjectType>;
126126
expect(Object.keys(typeMap.Post.getFields())).toContain('User');
127127
});
128128

129129
test('creates one field per reverse relationship', () => {
130130
const typeMap = getSchemaFromData(
131-
data,
131+
data
132132
).getTypeMap() as ObjMap<GraphQLObjectType>;
133133
expect(Object.keys(typeMap.User.getFields())).toContain('Posts');
134134
});
@@ -137,7 +137,7 @@ test('creates three query fields per data type', () => {
137137
// biome-ignore lint/style/noNonNullAssertion: It's only a test
138138
const queries = getSchemaFromData(data).getQueryType()!.getFields();
139139
expect((queries.Post.type as GraphQLObjectType).name).toEqual(
140-
PostType.name,
140+
PostType.name
141141
);
142142
expect(queries.Post.args).toEqual([
143143
expect.objectContaining({
@@ -159,7 +159,7 @@ test('creates three query fields per data type', () => {
159159
expect(queries._allPostsMeta.type.toString()).toEqual('ListMetadata');
160160

161161
expect((queries.User.type as GraphQLObjectType).name).toEqual(
162-
UserType.name,
162+
UserType.name
163163
);
164164
expect(queries.User.args).toEqual([
165165
expect.objectContaining({
@@ -185,7 +185,7 @@ test('creates three mutation fields per data type', () => {
185185
// biome-ignore lint/style/noNonNullAssertion: It's only a test
186186
const mutations = getSchemaFromData(data).getMutationType()!.getFields();
187187
expect((mutations.createPost.type as GraphQLObjectType).name).toEqual(
188-
PostType.name,
188+
PostType.name
189189
);
190190
expect(mutations.createPost.args).toEqual([
191191
expect.objectContaining({
@@ -202,7 +202,7 @@ test('creates three mutation fields per data type', () => {
202202
}),
203203
]);
204204
expect((mutations.updatePost.type as GraphQLObjectType).name).toEqual(
205-
PostType.name,
205+
PostType.name
206206
);
207207
expect(mutations.updatePost.args).toEqual([
208208
expect.objectContaining({
@@ -223,16 +223,25 @@ test('creates three mutation fields per data type', () => {
223223
}),
224224
]);
225225
expect((mutations.removePost.type as GraphQLObjectType).name).toEqual(
226-
PostType.name,
226+
PostType.name
227227
);
228228
expect(mutations.removePost.args).toEqual([
229229
expect.objectContaining({
230230
name: 'id',
231231
type: new GraphQLNonNull(GraphQLID),
232232
}),
233233
]);
234+
expect((mutations.deletePost.type as GraphQLObjectType).name).toEqual(
235+
PostType.name
236+
);
237+
expect(mutations.deletePost.args).toEqual([
238+
expect.objectContaining({
239+
name: 'id',
240+
type: new GraphQLNonNull(GraphQLID),
241+
}),
242+
]);
234243
expect((mutations.createUser.type as GraphQLObjectType).name).toEqual(
235-
UserType.name,
244+
UserType.name
236245
);
237246
expect(mutations.createUser.args).toEqual([
238247
expect.objectContaining({
@@ -241,7 +250,7 @@ test('creates three mutation fields per data type', () => {
241250
}),
242251
]);
243252
expect((mutations.updateUser.type as GraphQLObjectType).name).toEqual(
244-
UserType.name,
253+
UserType.name
245254
);
246255
expect(mutations.updateUser.args).toEqual([
247256
expect.objectContaining({
@@ -254,14 +263,23 @@ test('creates three mutation fields per data type', () => {
254263
}),
255264
]);
256265
expect((mutations.removeUser.type as GraphQLObjectType).name).toEqual(
257-
UserType.name,
266+
UserType.name
258267
);
259268
expect(mutations.removeUser.args).toEqual([
260269
expect.objectContaining({
261270
name: 'id',
262271
type: new GraphQLNonNull(GraphQLID),
263272
}),
264273
]);
274+
expect((mutations.deleteUser.type as GraphQLObjectType).name).toEqual(
275+
UserType.name
276+
);
277+
expect(mutations.deleteUser.args).toEqual([
278+
expect.objectContaining({
279+
name: 'id',
280+
type: new GraphQLNonNull(GraphQLID),
281+
}),
282+
]);
265283
});
266284

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

‎src/introspection/getSchemaFromData.ts

+8
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@ import type { Data } from '../types';
7272
* // createPost(data: String): Post
7373
* // updatePost(data: String): Post
7474
* // removePost(id: ID!): Boolean
75+
* // deletePost(id: ID!): Boolean
7576
* // createUser(data: String): User
7677
* // updateUser(data: String): User
7778
* // removeUser(id: ID!): Boolean
79+
* // deleteUser(id: ID!): Boolean
7880
* // }
7981
*/
8082
export default (data: Data) => {
@@ -196,6 +198,12 @@ export default (data: Data) => {
196198
id: { type: new GraphQLNonNull(GraphQLID) },
197199
},
198200
};
201+
fields[`delete${type.name}`] = {
202+
type: typesByName[type.name],
203+
args: {
204+
id: { type: new GraphQLNonNull(GraphQLID) },
205+
},
206+
};
199207
return fields;
200208
},
201209
{} as Record<string, any>,

‎src/resolver/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const getMutationResolvers = (entityName: string, data: Entity[]) => ({
2525
[`createMany${entityName}`]: createMany(data),
2626
[`update${entityName}`]: update(data),
2727
[`remove${entityName}`]: remove(data),
28+
[`delete${entityName}`]: remove(data),
2829
});
2930

3031
export default (data: Data) => {

0 commit comments

Comments
 (0)
Please sign in to comment.