add context test

This commit is contained in:
Nick Nance 2016-07-17 17:51:41 -07:00
parent 8a49a8bb66
commit 6633e52265
2 changed files with 23 additions and 1 deletions

View file

@ -81,6 +81,7 @@ export function apolloExpress(options: ApolloOptions | ExpressApolloOptionsFunct
schema: optionsObject.schema,
query: query,
variables: variables,
context: optionsObject.context,
rootValue: optionsObject.rootValue,
operationName: operationName,
logFunction: optionsObject.logFunction,

View file

@ -21,7 +21,10 @@ const QueryType = new GraphQLObjectType({
fields: {
testString: {
type: GraphQLString,
resolve() {
resolve(_, params, context) {
if (context) {
context();
}
return 'it works';
},
},
@ -274,6 +277,24 @@ export default (createApp: CreateAppFunc) => {
});
});
it('passes the context to the resolver', () => {
let results;
const expected = 'it works';
const app = createApp({apolloOptions: {
schema: Schema,
context: () => results = expected,
}});
const req = request(app)
.post('/graphql')
.send({
query: 'query test{ testString }',
});
return req.then((res) => {
expect(res.status).to.equal(200);
return expect(results).to.equal(expected);
});
});
});