Skip to content

Commit

Permalink
Update for [email protected] API
Browse files Browse the repository at this point in the history
- Actually call validationDidStart and parsingDidStart.

- Use new graphql-extensions API which:
  - replaces fooDidEnd with a handler returned by fooDidStart
  - adds options to various methods
  - has a new willSendResponse method
  - requires you to construct the extension objects yourself

- Make a better effort at consistently calling end handlers even on error
  • Loading branch information
glasser committed May 30, 2018
1 parent fcf3d3c commit ae9c187
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 146 deletions.
4 changes: 2 additions & 2 deletions packages/apollo-server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
},
"dependencies": {
"apollo-cache-control": "^0.1.1",
"apollo-tracing": "^0.1.0",
"graphql-extensions": "^0.0.x",
"apollo-tracing": "^0.2.0-beta.0",
"graphql-extensions": "0.1.0-beta.7",
"graphql-subscriptions": "^0.5.8",
"graphql-tools": "^3.0.2",
"subscriptions-transport-ws": "^0.9.9",
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-server-core/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
ValidationContext,
FieldDefinitionNode,
} from 'graphql';
import { GraphQLExtension } from 'graphql-extensions';

import { ApolloEngine } from 'apollo-engine';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-server-core/src/graphqlOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { GraphQLExtension } from 'graphql-extensions';
* - (optional) formatResponse: a function applied to each graphQL execution result
* - (optional) fieldResolver: a custom default field resolver
* - (optional) debug: a boolean that will print additional debug logging if execution errors occur
* - (optional) extensions: an array of GraphQLExtension
* - (optional) extensions: an array of GraphQLExtensions
*
*/
export interface GraphQLServerOptions<
Expand All @@ -40,7 +40,7 @@ export interface GraphQLServerOptions<
tracing?: boolean;
// cacheControl?: boolean | CacheControlExtensionOptions;
cacheControl?: boolean | any;
extensions?: Array<typeof GraphQLExtension | GraphQLExtension>;
extensions?: Array<GraphQLExtension>;
}

export default GraphQLServerOptions;
Expand Down
18 changes: 12 additions & 6 deletions packages/apollo-server-core/src/runQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,9 @@ describe('runQuery', () => {
}

it('creates the extension stack', async () => {
const query = `{ testString }`;
const queryString = `{ testString }`;
const expected = { testString: 'it works' };
const extensions = [CustomExtension];
const extensions = [new CustomExtension()];
return runQuery({
schema: new GraphQLSchema({
query: new GraphQLObjectType({
Expand All @@ -397,16 +397,22 @@ describe('runQuery', () => {
},
}),
}),
query,
queryString,
extensions,
request: new MockReq(),
});
});

it('runs format response from extensions', async () => {
const query = `{ testString }`;
const queryString = `{ testString }`;
const expected = { testString: 'it works' };
const extensions = [CustomExtension];
return runQuery({ schema, query: query, extensions }).then(res => {
const extensions = [new CustomExtension()];
return runQuery({
schema,
queryString,
extensions,
request: new MockReq(),
}).then(res => {
return expect(res.extensions).to.deep.equal({
customExtension: { foo: 'bar' },
});
Expand Down
Loading

0 comments on commit ae9c187

Please sign in to comment.