Skip to content
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

feat: Expose document representation of sub-query request within GraphQLDataSourceProcessOptions so that it is available to RemoteGraphQLDataSource.process and RemoteGraphQLDataSource.willSendRequest #1878

Merged
merged 2 commits into from
Jul 1, 2022
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions gateway-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The Federation v0.x equivalent for this package can be found [here](https://github.com/apollographql/federation/blob/version-0.x/gateway-js/CHANGELOG.md) on the `version-0.x` branch of this repo.

- Expose document representation of sub-query request within GraphQLDataSourceProcessOptions so that it is available to RemoteGraphQLDataSource.process and RemoteGraphQLDataSource.willSendRequest [PR#1878](https://github.com/apollographql/federation/pull/1878)
- Fix issue when using a type condition on an inaccessible type in `@require` [#1873](https://github.com/apollographql/federation/pull/1873).
- __BREAKING__: this fix required passing a new argument to the `executeQueryPlan` method, which is technically
exported by the gateway. Most users of the gateway should _not_ call this method directly (which is exported mainly
Expand Down
2 changes: 1 addition & 1 deletion gateway-js/src/__tests__/execution-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export function getFederatedTestingSchema(services: ServiceDefinitionModule[] =
throw new GraphQLSchemaValidationError(compositionResult.errors);
}

const queryPlanner = new QueryPlanner(compositionResult.schema);
const queryPlanner = new QueryPlanner(compositionResult.schema, { exposeDocumentNodeInFetchNode: false} );
const schema = buildSchema(compositionResult.supergraphSdl);

const serviceMap = Object.fromEntries(
Expand Down
4 changes: 4 additions & 0 deletions gateway-js/src/datasources/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export type GraphQLDataSourceProcessOptions<
* checking `kind`).
*/
context: GraphQLRequestContext<TContext>['context'];
/**
* The document representation of the request's query being sent to the subgraph, if available.
*/
document?: GraphQLRequestContext<TContext>['document'];
}
| {
kind:
Expand Down
11 changes: 8 additions & 3 deletions gateway-js/src/executeQueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
isObjectType,
isInterfaceType,
GraphQLErrorOptions,
DocumentNode,
} from 'graphql';
import { Trace, google } from 'apollo-reporting-protobuf';
import { GraphQLDataSource, GraphQLDataSourceRequestKind } from './datasources/types';
Expand Down Expand Up @@ -298,7 +299,8 @@ async function executeFetch<TContext>(
context,
fetch.operation,
variables,
fetch.operationName
fetch.operationName,
fetch.operationDocumentNode
);

for (const entity of entities) {
Expand Down Expand Up @@ -337,7 +339,8 @@ async function executeFetch<TContext>(
context,
fetch.operation,
{...variables, representations},
fetch.operationName
fetch.operationName,
fetch.operationDocumentNode
);

if (!dataReceivedFromService) {
Expand Down Expand Up @@ -379,7 +382,8 @@ async function executeFetch<TContext>(
context: ExecutionContext<TContext>,
source: string,
variables: Record<string, any>,
operationName: string | undefined
operationName: string | undefined,
operationDocumentNode?: DocumentNode
): Promise<ResultMap | void | null> {
// We declare this as 'any' because it is missing url and method, which
// GraphQLRequest.http is supposed to have if it exists.
Expand Down Expand Up @@ -417,6 +421,7 @@ async function executeFetch<TContext>(
},
incomingRequestContext: context.requestContext,
context: context.requestContext.context,
document: operationDocumentNode
});

if (response.errors) {
Expand Down
2 changes: 2 additions & 0 deletions query-planner-js/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

This CHANGELOG pertains only to Apollo Federation packages in the 2.x range. The Federation v0.x equivalent for this package can be found [here](https://github.com/apollographql/federation/blob/version-0.x/query-planner-js/CHANGELOG.md) on the `version-0.x` branch of this repo.

- Expose document representation of sub-query request within GraphQLDataSourceProcessOptions so that it is available to RemoteGraphQLDataSource.process and RemoteGraphQLDataSource.willSendRequest [PR#1878](https://github.com/apollographql/federation/pull/1878)

## 2.1.0-alpha.0

- Expand support for Node.js v18 [PR #1884](https://github.com/apollographql/federation/pull/1884)
Expand Down
2 changes: 2 additions & 0 deletions query-planner-js/src/QueryPlan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Kind,
SelectionNode as GraphQLJSSelectionNode,
OperationTypeNode,
DocumentNode,
} from 'graphql';
import prettyFormat from 'pretty-format';
import { queryPlanSerializer, astSerializer } from './snapshotSerializers';
Expand Down Expand Up @@ -33,6 +34,7 @@ export interface FetchNode {
operation: string;
operationName: string | undefined;
operationKind: OperationTypeNode;
operationDocumentNode?: DocumentNode;
}

export interface FlattenNode {
Expand Down
4 changes: 2 additions & 2 deletions query-planner-js/src/__tests__/allFeatures.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ for (const directory of directories) {
beforeAll(() => {
const supergraphSdl = fs.readFileSync(schemaPath, 'utf8');
schema = buildSchema(supergraphSdl);
queryPlanner = new QueryPlanner(schema);
const exposeDocumentNodeInFetchNode = feature.title.endsWith("(with ExposeDocumentNodeInFetchNode)");
queryPlanner = new QueryPlanner(schema, { exposeDocumentNodeInFetchNode: exposeDocumentNodeInFetchNode});
});

feature.scenarios.forEach((scenario) => {
Expand All @@ -65,7 +66,6 @@ for (const directory of directories) {
queryPlan = queryPlanner.buildQueryPlan(operation);

const expectedQueryPlan = JSON.parse(expectedQueryPlanString);

expect(queryPlan).toMatchQueryPlan(expectedQueryPlan);
});
};
Expand Down
Loading