Skip to content

Commit 4b047ff

Browse files
authored
Merge pull request #104 from underscore05/richard/fix-non-incremental-id-and-remove-schema-return-type
Fix issue with Remove and Create function not incrementing the ID
2 parents 685a1c0 + fe47b30 commit 4b047ff

File tree

3 files changed

+3
-15
lines changed

3 files changed

+3
-15
lines changed

src/introspection/getSchemaFromData.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,10 @@ export default (data) => {
139139
},
140140
{}
141141
);
142+
const { id, ...createFields } = typeFields;
142143
fields[`create${type.name}`] = {
143144
type: typesByName[type.name],
144-
args: typeFields,
145+
args: createFields,
145146
};
146147
fields[`update${type.name}`] = {
147148
type: typesByName[type.name],

src/introspection/getSchemaFromData.spec.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,6 @@ test('creates three mutation fields per data type', () => {
175175
const mutations = getSchemaFromData(data).getMutationType().getFields();
176176
expect(mutations['createPost'].type.name).toEqual(PostType.name);
177177
expect(mutations['createPost'].args).toEqual([
178-
{
179-
name: 'id',
180-
type: new GraphQLNonNull(GraphQLID),
181-
defaultValue: undefined,
182-
description: null,
183-
},
184178
{
185179
name: 'title',
186180
type: new GraphQLNonNull(GraphQLString),
@@ -238,12 +232,6 @@ test('creates three mutation fields per data type', () => {
238232
]);
239233
expect(mutations['createUser'].type.name).toEqual(UserType.name);
240234
expect(mutations['createUser'].args).toEqual([
241-
{
242-
name: 'id',
243-
type: new GraphQLNonNull(GraphQLID),
244-
defaultValue: undefined,
245-
description: null,
246-
},
247235
{
248236
name: 'name',
249237
type: new GraphQLNonNull(GraphQLString),

src/resolver/Mutation/create.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
export default (entityData = []) => (_, entity) => {
22
const newId =
33
entityData.length > 0 ? entityData[entityData.length - 1].id + 1 : 0;
4-
const newEntity = Object.assign({ id: newId }, entity);
5-
4+
const newEntity = Object.assign({}, entity, { id: newId });
65
entityData.push(newEntity);
76
return newEntity;
87
};

0 commit comments

Comments
 (0)