mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 10:11:40 -05:00
add context test
This commit is contained in:
parent
8a49a8bb66
commit
6633e52265
2 changed files with 23 additions and 1 deletions
|
@ -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,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue