Skip to content

Commit

Permalink
Merge pull request apollographql#50 from apollostack/add-context
Browse files Browse the repository at this point in the history
Add context support to Express
  • Loading branch information
nnance authored Jul 19, 2016
2 parents 8a49a8b + 6633e52 commit f2bc41c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/integrations/expressApollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 22 additions & 1 deletion src/integrations/integrations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const QueryType = new GraphQLObjectType({
fields: {
testString: {
type: GraphQLString,
resolve() {
resolve(_, params, context) {
if (context) {
context();
}
return 'it works';
},
},
Expand Down Expand Up @@ -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);
});
});

});


Expand Down

0 comments on commit f2bc41c

Please sign in to comment.