Skip to content

Commit

Permalink
Revert "Pass the context request and response extension methods (#1547)"
Browse files Browse the repository at this point in the history
This reverts commit 408198e.
  • Loading branch information
abernix committed Sep 27, 2018
1 parent 68c82e6 commit 2b470e1
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 49 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

### vNEXT

- FIXME(@abernix): Allow context to be passed to all GraphQLExtension methods.
- FIXME(@abernix): client info in traces.
- Allow an optional function to resolve the `rootValue`, passing the `DocumentNode` AST to determine the value. [PR #1555](https://github.com/apollographql/apollo-server/pull/1555)
- Follow-up on the work in [PR #1516](https://github.com/apollographql/apollo-server/pull/1516) to also fix missing insertion cursor/caret when a custom GraphQL configuration is specified which doesn't specify its own `cursorShape` property. [PR #1607](https://github.com/apollographql/apollo-server/pull/1607)
Expand Down
4 changes: 2 additions & 2 deletions packages/apollo-engine-reporting/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class EngineReportingExtension<TContext = any>
request: Request;
queryString?: string;
parsedQuery?: DocumentNode;
variables?: Record<string, any>;
variables: Record<string, any>;
persistedQueryHit?: boolean;
persistedQueryRegister?: boolean;
}): EndHandler {
Expand Down Expand Up @@ -140,7 +140,7 @@ export class EngineReportingExtension<TContext = any>
} else {
try {
this.trace.details!.variablesJson![name] = JSON.stringify(
o.variables![name],
o.variables[name],
);
} catch (e) {
// This probably means that the value contains a circular reference,
Expand Down
22 changes: 0 additions & 22 deletions packages/apollo-server-core/src/__tests__/runQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,28 +370,6 @@ describe('runQuery', () => {
});
});
});

it('runs willSendResponse with extensions context', async () => {
class CustomExtension implements GraphQLExtension<any> {
willSendResponse(o: any) {
expect(o).toHaveProperty('context.baz', 'always here');
return o;
}
}

const queryString = `{ testString }`;
const expected = { testString: 'it works' };
const extensions = [() => new CustomExtension()];
return runQuery({
schema,
queryString,
context: { baz: 'always here' },
extensions,
request: new MockReq(),
}).then(res => {
expect(res.data).toEqual(expected);
});
});
});

describe('async_hooks', () => {
Expand Down
6 changes: 2 additions & 4 deletions packages/apollo-server-core/src/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { GraphQLExtension, GraphQLResponse } from 'graphql-extensions';
import { formatApolloErrors } from 'apollo-server-errors';

export class FormatErrorExtension<TContext = any> extends GraphQLExtension {
export class FormatErrorExtension extends GraphQLExtension {
private formatError: Function;
private debug: boolean;

Expand All @@ -13,11 +13,9 @@ export class FormatErrorExtension<TContext = any> extends GraphQLExtension {

public willSendResponse(o: {
graphqlResponse: GraphQLResponse;
context: TContext;
}): void | { graphqlResponse: GraphQLResponse; context: TContext } {
}): void | { graphqlResponse: GraphQLResponse } {
if (o.graphqlResponse.errors) {
return {
...o,
graphqlResponse: {
...o.graphqlResponse,
errors: formatApolloErrors(o.graphqlResponse.errors, {
Expand Down
6 changes: 1 addition & 5 deletions packages/apollo-server-core/src/runQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ function doRunQuery(options: QueryOptions): Promise<GraphQLResponse> {
variables: options.variables,
persistedQueryHit: options.persistedQueryHit,
persistedQueryRegister: options.persistedQueryRegister,
context,
});
return Promise.resolve()
.then(
Expand Down Expand Up @@ -282,10 +281,7 @@ function doRunQuery(options: QueryOptions): Promise<GraphQLResponse> {
throw err;
})
.then((graphqlResponse: GraphQLResponse) => {
const response = extensionStack.willSendResponse({
graphqlResponse,
context,
});
const response = extensionStack.willSendResponse({ graphqlResponse });
requestDidEnd();
return response.graphqlResponse;
});
Expand Down
14 changes: 4 additions & 10 deletions packages/apollo-server-integration-testsuite/src/ApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,8 @@ export function testApolloServer<AS extends ApolloServerBase>(
return error;
});

class Extension<TContext = any> extends GraphQLExtension {
willSendResponse(o: {
graphqlResponse: GraphQLResponse;
context: TContext;
}) {
class Extension extends GraphQLExtension {
willSendResponse(o: { graphqlResponse: GraphQLResponse }) {
expect(o.graphqlResponse.errors.length).toEqual(1);
// formatError should be called after extensions
expect(formatError).not.toBeCalled();
Expand Down Expand Up @@ -612,11 +609,8 @@ export function testApolloServer<AS extends ApolloServerBase>(
return error;
});

class Extension<TContext = any> extends GraphQLExtension {
willSendResponse(_o: {
graphqlResponse: GraphQLResponse;
context: TContext;
}) {
class Extension extends GraphQLExtension {
willSendResponse(_o: { graphqlResponse: GraphQLResponse }) {
// formatError should be called after extensions
expect(formatError).not.toBeCalled();
extension();
Expand Down
8 changes: 2 additions & 6 deletions packages/graphql-extensions/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export class GraphQLExtension<TContext = any> {
variables?: { [key: string]: any };
persistedQueryHit?: boolean;
persistedQueryRegister?: boolean;
context: TContext;
}): EndHandler | void;
public parsingDidStart?(o: { queryString: string }): EndHandler | void;
public validationDidStart?(): EndHandler | void;
Expand All @@ -50,8 +49,7 @@ export class GraphQLExtension<TContext = any> {

public willSendResponse?(o: {
graphqlResponse: GraphQLResponse;
context: TContext;
}): void | { graphqlResponse: GraphQLResponse; context: TContext };
}): void | { graphqlResponse: GraphQLResponse };

public willResolveField?(
source: any,
Expand Down Expand Up @@ -80,7 +78,6 @@ export class GraphQLExtensionStack<TContext = any> {
variables?: { [key: string]: any };
persistedQueryHit?: boolean;
persistedQueryRegister?: boolean;
context: TContext;
}): EndHandler {
return this.handleDidStart(
ext => ext.requestDidStart && ext.requestDidStart(o),
Expand All @@ -107,8 +104,7 @@ export class GraphQLExtensionStack<TContext = any> {

public willSendResponse(o: {
graphqlResponse: GraphQLResponse;
context: TContext;
}): { graphqlResponse: GraphQLResponse; context: TContext } {
}): { graphqlResponse: GraphQLResponse } {
let reference = o;
// Reverse the array, since this is functions as an end handler
[...this.extensions].reverse().forEach(extension => {
Expand Down

0 comments on commit 2b470e1

Please sign in to comment.