mirror of
https://github.com/vale981/apollo-server
synced 2025-03-06 02:01:40 -05:00
Revert "Pass the context request and response extension methods (#1547)"
This reverts commit 408198e5ac
.
This commit is contained in:
parent
68c82e63c6
commit
2b470e1c11
7 changed files with 12 additions and 49 deletions
|
@ -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)
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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,
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
@ -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, {
|
||||
|
|
|
@ -135,7 +135,6 @@ function doRunQuery(options: QueryOptions): Promise<GraphQLResponse> {
|
|||
variables: options.variables,
|
||||
persistedQueryHit: options.persistedQueryHit,
|
||||
persistedQueryRegister: options.persistedQueryRegister,
|
||||
context,
|
||||
});
|
||||
return Promise.resolve()
|
||||
.then(
|
||||
|
@ -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;
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
@ -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,
|
||||
|
@ -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),
|
||||
|
@ -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 => {
|
||||
|
|
Loading…
Add table
Reference in a new issue