Skip to content

Commit 8154df3

Browse files
committed
feat: add actual create many test, fix shallow clone issue.
1 parent 9b3989a commit 8154df3

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/introspection/getSchemaFromData.js

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

145145
// Build input type.
146-
var inputFields = { ...typeFields };
147-
Object.keys(inputFields).forEach((key) => {
148-
delete inputFields[key].resolve;
149-
});
150-
var inputType = new GraphQLInputObjectType({
146+
const inputFields = Object.keys(typeFields).reduce(
147+
(f, fieldName) => {
148+
f[fieldName] = Object.assign({}, typeFields[fieldName]);
149+
delete f[fieldName].resolve;
150+
return f;
151+
},
152+
{}
153+
);
154+
155+
console.log(typeFields);
156+
const createManyInputType = new GraphQLInputObjectType({
151157
name: type.name + 'Input',
152158
fields: inputFields,
153159
});
@@ -160,7 +166,7 @@ export default (data) => {
160166
type: new GraphQLList(typesByName[type.name]),
161167
args: {
162168
data: {
163-
type: new GraphQLList(inputType),
169+
type: new GraphQLList(createManyInputType),
164170
},
165171
},
166172
};

src/resolver/Mutation/createMany.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ test('creates a new record', () => {
2424
createMany(data)(null, { data: [{ value: 'foo' }] });
2525
expect(data).toEqual([{ id: 1 }, { id: 3 }, { id: 4, value: 'foo' }]);
2626
});
27+
28+
test('creates multiple new records', () => {
29+
const data = [{ id: 1 }, { id: 3 }];
30+
createMany(data)(null, {
31+
data: [{ value: 'foo' }, { value: 'bar' }, { value: 'baz' }],
32+
});
33+
expect(data).toEqual([
34+
{ id: 1 },
35+
{ id: 3 },
36+
{ id: 4, value: 'foo' },
37+
{ id: 5, value: 'bar' },
38+
{ id: 6, value: 'baz' },
39+
]);
40+
});

0 commit comments

Comments
 (0)