Skip to content

Commit

Permalink
added a test for rootValue and updated mutationFn
Browse files Browse the repository at this point in the history
  • Loading branch information
flipside committed Apr 15, 2016
1 parent 427d32d commit 0f54efb
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
54 changes: 53 additions & 1 deletion src/mutation/__tests__/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,24 @@ var simplePromiseMutation = mutationWithClientMutationId({
mutateAndGetPayload: () => Promise.resolve({result: 1})
});

var simpleRootValueMutation = mutationWithClientMutationId({
name: 'SimpleRootValueMutation',
inputFields: {},
outputFields: {
result: {
type: GraphQLInt
}
},
mutateAndGetPayload: (params, context, {rootValue}) => (rootValue)
});

var mutation = new GraphQLObjectType({
name: 'Mutation',
fields: {
simpleMutation: simpleMutation,
simpleMutationWithThunkFields: simpleMutationWithThunkFields,
simplePromiseMutation: simplePromiseMutation
simplePromiseMutation: simplePromiseMutation,
simpleRootValueMutation: simpleRootValueMutation
}
});

Expand Down Expand Up @@ -145,6 +157,26 @@ describe('mutationWithClientMutationId()', () => {
return expect(graphql(schema, query)).to.become(expected);
});

it('can access rootValue', () => {
var query = `
mutation M {
simpleRootValueMutation(input: {clientMutationId: "abc"}) {
result
clientMutationId
}
}
`;
var expected = {
data: {
simpleRootValueMutation: {
result: 1,
clientMutationId: 'abc'
}
}
};
return expect(graphql(schema, query, {result: 1})).to.become(expected);
});

describe('introspection', () => {
it('contains correct input', () => {
var query = `{
Expand Down Expand Up @@ -325,6 +357,26 @@ describe('mutationWithClientMutationId()', () => {
kind: 'OBJECT',
}
},
{
name: 'simpleRootValueMutation',
args: [
{
name: 'input',
type: {
name: null,
kind: 'NON_NULL',
ofType: {
name: 'SimpleRootValueMutationInput',
kind: 'INPUT_OBJECT'
}
},
}
],
type: {
name: 'SimpleRootValueMutationPayload',
kind: 'OBJECT',
}
},
]
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/mutation/mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import type {
GraphQLResolveInfo
} from 'graphql';

type mutationFn = (object: Object, info: GraphQLResolveInfo) => Object |
(object: Object, info: GraphQLResolveInfo) => Promise<Object>;
type mutationFn =
(object: Object, ctx: Object, info: GraphQLResolveInfo) => Object |
(object: Object, ctx: Object, info: GraphQLResolveInfo) => Promise<Object>;

function resolveMaybeThunk<T>(thingOrThunk: T | () => T): T {
return typeof thingOrThunk === 'function' ? thingOrThunk() : thingOrThunk;
Expand Down

0 comments on commit 0f54efb

Please sign in to comment.