Skip to content

Commit 1c5690e

Browse files
authored
Merge pull request #141 from marmelab/132-create-mutation-does-not-require-id-but-createmany-mutation-does
Fix createMany Input Type requiring an id
2 parents 06332be + 625050b commit 1c5690e

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/introspection/getSchemaFromData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ export default (data) => {
143143
const { id, ...createFields } = typeFields;
144144

145145
// Build input type.
146-
const inputFields = Object.keys(typeFields).reduce(
146+
const inputFields = Object.keys(createFields).reduce(
147147
(f, fieldName) => {
148-
f[fieldName] = Object.assign({}, typeFields[fieldName]);
148+
f[fieldName] = Object.assign({}, createFields[fieldName]);
149149
delete f[fieldName].resolve;
150150
return f;
151151
},

src/introspection/getSchemaFromData.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,38 @@ test('creates three mutation fields per data type', () => {
265265
]);
266266
});
267267

268+
test('creates the mutation *Input type for createMany', () => {
269+
const mutations = getSchemaFromData(data).getMutationType().getFields();
270+
const createManyPostInputType = mutations['createManyPost'].args[0].type;
271+
expect(createManyPostInputType.toString()).toEqual('[PostInput]');
272+
expect(createManyPostInputType.ofType.getFields()).toEqual({
273+
title: {
274+
type: new GraphQLNonNull(GraphQLString),
275+
name: 'title',
276+
astNode: undefined,
277+
defaultValue: undefined,
278+
description: undefined,
279+
extensions: undefined,
280+
},
281+
views: {
282+
type: new GraphQLNonNull(GraphQLInt),
283+
name: 'views',
284+
astNode: undefined,
285+
defaultValue: undefined,
286+
description: undefined,
287+
extensions: undefined,
288+
},
289+
user_id: {
290+
type: new GraphQLNonNull(GraphQLID),
291+
name: 'user_id',
292+
astNode: undefined,
293+
defaultValue: undefined,
294+
description: undefined,
295+
extensions: undefined,
296+
},
297+
});
298+
});
299+
268300
test('pluralizes and capitalizes correctly', () => {
269301
const data = {
270302
feet: [

0 commit comments

Comments
 (0)