Skip to content

Commit

Permalink
feat: expose subquery operation document node
Browse files Browse the repository at this point in the history
  • Loading branch information
theJC committed Jul 1, 2022
1 parent d8a8564 commit fa69b13
Show file tree
Hide file tree
Showing 9 changed files with 621 additions and 271 deletions.
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/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

0 comments on commit fa69b13

Please sign in to comment.