Skip to content

Commit

Permalink
feat(update): change update payload format
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Oct 20, 2015
1 parent 3255ab9 commit 691cc71
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/e2e.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,18 @@ describe('e2e', () => {
result = await graphql(schema, `
mutation updateUserMutation {
updateUser(input: {id: "${id}", name: "Updated Test User", clientMutationId: "2"}) {
name
changedUser {
name
}
}
}
`);
expect(result).to.containSubset({
data: {
updateUser: {
name: 'Updated Test User'
changedUser: {
name: 'Updated Test User'
}
}
}
});
Expand Down
14 changes: 12 additions & 2 deletions src/schema/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ function getMutationField(graffitiModel, type, viewer) {
}, {});

const Name = name[0].toUpperCase() + name.slice(1);
const edgeName = `changed${Name}Edge`;
const changedName = `changed${Name}`;
const edgeName = `${changedName}Edge`;

const addName = `add${name}`;
const updateName = `update${name}`;
Expand Down Expand Up @@ -160,7 +161,15 @@ function getMutationField(graffitiModel, type, viewer) {
...inputFields,
id: idField
},
outputFields: fields,
outputFields: {
[changedName]: {
type: new GraphQLObjectType({
fields,
name: changedName
}),
resolve: (node) => node
}
},
mutateAndGetPayload: getUpdateOneMutateHandler(graffitiModel)
}),
[deleteName]: mutationWithClientMutationId({
Expand All @@ -169,6 +178,7 @@ function getMutationField(graffitiModel, type, viewer) {
id: idField
},
outputFields: {
viewer,
ok: {
type: GraphQLBoolean
},
Expand Down

0 comments on commit 691cc71

Please sign in to comment.