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(gateway): Integrate WASM Query Planner #4534

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
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,34 @@ describe('composeServices', () => {
expect(stream).toMatchInlineSnapshot(`"@stream"`);
});
});

it('extensions field on GraphQLSchema includes serviceList', () => {
const serviceA = {
typeDefs: gql`
type Product {
sku: String!
name: String!
}
`,
name: 'serviceA',
};

const serviceB = {
typeDefs: gql`
type User {
name: String
email: String!
}
`,
name: 'serviceB',
};

const { schema, errors } = composeServices([serviceA, serviceB]);
expect(errors).toHaveLength(0);
expect(schema).toBeDefined();
expect(schema.extensions.serviceList).toBeDefined();
expect(schema.extensions.serviceList).toHaveLength(2);
});
});

// XXX Ignored/unimplemented spec tests
Expand Down
9 changes: 8 additions & 1 deletion packages/apollo-federation/src/composition/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ export interface KeyDirectivesMap {
* shared across at least 2 services.
*/
type ValueTypes = Set<string>;

export type ComposedGraphQLSchema = GraphQLSchema & {
extensions: { serviceList: ServiceDefinition[] }
};
/**
* Loop over each service and process its typeDefs (`definitions`)
* - build up typeToServiceMap
Expand Down Expand Up @@ -617,6 +621,9 @@ export function composeServices(services: ServiceDefinition[]) {
? (schema.getType(typeName) as GraphQLObjectType<any, any>)
: undefined,
),
extensions: {
serviceList: services
}
});

// If multiple type definitions and extensions for the same type implement the
Expand Down Expand Up @@ -648,5 +655,5 @@ export function composeServices(services: ServiceDefinition[]) {
* and every field that was extended. Fields that were _not_ extended (added on the base type by the owner),
* there is no `serviceName`, and we should refer to the type's `serviceName`
*/
return { schema, errors };
return { schema: schema as ComposedGraphQLSchema, errors };
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { fixtures } from 'apollo-federation-integration-testsuite';
import { composeAndValidate } from '../../composition';
import { parse, print, GraphQLError, visit, StringValueNode } from 'graphql';
import { parse, GraphQLError, visit, StringValueNode } from 'graphql';

describe('printComposedSdl', () => {
let composedSdl: string, errors: GraphQLError[];
let composedSdl: string | undefined, errors: GraphQLError[];

beforeAll(() => {
// composeAndValidate calls `printComposedSdl` to return `composedSdl`
Expand All @@ -15,7 +15,7 @@ describe('printComposedSdl', () => {
});

it('produces a parseable output', () => {
expect(() => parse(composedSdl)).not.toThrow();
expect(() => parse(composedSdl!)).not.toThrow();
})

it('prints a fully composed schema correctly', () => {
Expand Down Expand Up @@ -291,7 +291,7 @@ describe('printComposedSdl', () => {
});

it('fieldsets are parseable', () => {
const parsedCsdl = parse(composedSdl);
const parsedCsdl = parse(composedSdl!);
const fieldSets: string[] = [];

// Collect all args with the 'fields' name (from @key, @provides, @requires directives)
Expand Down
1 change: 1 addition & 0 deletions packages/apollo-gateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
},
"dependencies": {
"@apollo/federation": "file:../apollo-federation",
"@apollo/query-planner-wasm": "0.0.2",
"@types/node-fetch": "2.5.4",
"apollo-engine-reporting-protobuf": "file:../apollo-engine-reporting-protobuf",
"apollo-env": "^0.6.1",
Expand Down
169 changes: 0 additions & 169 deletions packages/apollo-gateway/src/FieldSet.ts

This file was deleted.

10 changes: 7 additions & 3 deletions packages/apollo-gateway/src/QueryPlan.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import {
FragmentDefinitionNode,
GraphQLSchema,
OperationDefinitionNode,
Kind,
SelectionNode as GraphQLJSSelectionNode,
} from 'graphql';
import prettyFormat from 'pretty-format';
import { queryPlanSerializer, astSerializer } from './snapshotSerializers';
import { ComposedGraphQLSchema } from '@apollo/federation';

export type ResponsePath = (string | number)[];

export type FragmentMap = { [fragmentName: string]: FragmentDefinitionNode };
export type WasmPointer = number;

type FragmentMap = { [fragmentName: string]: FragmentDefinitionNode };

export type OperationContext = {
schema: GraphQLSchema;
schema: ComposedGraphQLSchema;
operation: OperationDefinitionNode;
fragments: FragmentMap;
queryPlannerPointer: WasmPointer;
operationString: string;
};

export interface QueryPlan {
Expand Down
Loading