Skip to content

Narrow willSendRequest's parameter type #161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions gateway-js/src/datasources/RemoteGraphQLDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import { isObject } from '../utilities/predicates';
import { GraphQLDataSource } from './types';
import createSHA from 'apollo-server-core/dist/utils/createSHA';

type GraphQLRequestWithHttp = GraphQLRequest & Required<Pick<GraphQLRequest, 'http'>>;

export class RemoteGraphQLDataSource<TContext extends Record<string, any> = Record<string, any>> implements GraphQLDataSource<TContext> {
fetcher: typeof fetch = fetch;

Expand Down Expand Up @@ -71,7 +73,10 @@ export class RemoteGraphQLDataSource<TContext extends Record<string, any> = Reco
};

if (this.willSendRequest) {
await this.willSendRequest({ request, context });
await this.willSendRequest({
request: request as GraphQLRequestWithHttp,
context
});
}

if (!request.query) {
Expand Down Expand Up @@ -172,10 +177,10 @@ export class RemoteGraphQLDataSource<TContext extends Record<string, any> = Reco
}

public willSendRequest?(
requestContext: Pick<
GraphQLRequestContext<TContext>,
'request' | 'context'
>,
requestContext: {
request: GraphQLRequestWithHttp,
context: TContext
},
): ValueOrPromise<void>;

public didReceiveResponse?(
Expand Down