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

Core schema support and Typescript query planner redux #622

Merged
merged 51 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
1322e44
Initial copy/paste for simpler diffing against
trevor-scheer Mar 18, 2021
0aa65fb
Implement core spec
trevor-scheer Mar 18, 2021
f1e0a8a
Initial impl of join spec
trevor-scheer Mar 18, 2021
f9f3784
Implement http directive for join__Graph enum
trevor-scheer Mar 19, 2021
06c42ad
Re-introduce last used TypeScript query planner code
martijnwalraven Mar 19, 2021
9a1e715
Use Federation metadata from composed schema
martijnwalraven Mar 19, 2021
9dab51d
Copy feature tests from Rust query planner to `@apollo/query-planner`…
martijnwalraven Mar 19, 2021
9af5533
Fix discrepancy in schema used for feature test
martijnwalraven Mar 19, 2021
ac540d2
Add `isNotNullOrUndefined` and remove dependency on `apollo-env`
martijnwalraven Mar 19, 2021
d2ef7c6
Change `getBaseService` and `getOwningService` to return `undefined` …
martijnwalraven Mar 19, 2021
4911364
Treat abstract types as value types to replicate type explosion fix
martijnwalraven Mar 19, 2021
5b8dc42
Make test pass by removing code that changes field ordering
martijnwalraven Mar 19, 2021
439fad2
Disable test for propagation of directives on inline fragments
martijnwalraven Mar 19, 2021
6cb2023
Update ordering of fragments in snapshots for autofragmentization tests
martijnwalraven Mar 19, 2021
b9f3a7c
Merge branch 'trevor/print-core-schema' into typescript-redux
martijnwalraven Mar 21, 2021
a09e433
Print valid core schema and change `@http` to `@join__endpoint`
martijnwalraven Mar 21, 2021
cbbf8cb
Adapt query planner to core schema input
martijnwalraven Mar 21, 2021
081c59e
Skip tests that fail because of value type handling in composition
martijnwalraven Mar 21, 2021
1e324f2
Print valid core schema and change `@http` to `@join__endpoint`
martijnwalraven Mar 21, 2021
eadfe94
Remove copy/pasta extension code from both composed and core printers
trevor-scheer Mar 22, 2021
2313d5a
Reintroduce fieldSet parseability test
trevor-scheer Mar 22, 2021
37773db
Cleanup test case
trevor-scheer Mar 22, 2021
166bce7
Merge branch 'trevor/print-core-schema' into typescript-redux
martijnwalraven Mar 23, 2021
bf79bec
Filter out core and join elements in `buildComposedSchema`
martijnwalraven Mar 24, 2021
70dce5c
Make the `graph` argument in `join__owner` and `join__type` non-nullable
martijnwalraven Mar 24, 2021
80e4431
Make `@provides` on value types work by printing `@join__field` witho…
martijnwalraven Mar 24, 2021
63658b8
Avoid printing `@join__field` for what should be value types
martijnwalraven Mar 24, 2021
0365de6
Change `@join__endpoint(serviceName:url:)` to `@join__graph(name:url:)`
martijnwalraven Mar 24, 2021
0b133e5
Uniquify and sanitize enum values in the join__Graph enum
trevor-scheer Mar 24, 2021
1b2af2d
Always invoke `GraphQLNonNull` as a constructor
martijnwalraven Mar 25, 2021
31a7ba6
Propagate directives on inline fragments to subqueries
martijnwalraven Mar 25, 2021
88f8c09
Escape string literals when printing core schema
martijnwalraven Mar 28, 2021
3350d86
Fix bug in the type explosion workaround code
martijnwalraven Mar 29, 2021
9cb48f1
Rename leftover endpointDirectiveArgs to graphDirectiveArgs
martijnwalraven Mar 29, 2021
4b7df18
Add hard coded feature and version checking for core schema
martijnwalraven Mar 29, 2021
3f860e3
harmonizer: Update to use `coreSchema` rather than `composedSdl`.
abernix Mar 30, 2021
da7a186
chore(harmonizer): Bump minor version to reflect new output
abernix Mar 30, 2021
25b5453
Make context a required arg everywhere, pass to printInterface
trevor-scheer Mar 30, 2021
973db23
Print @join__type directives on interface types
trevor-scheer Mar 30, 2021
22e6e77
Remove CSDL
trevor-scheer Mar 30, 2021
eb6676b
fix(gateway): Address typings issue for getDefaultFetcher (#585)
trevor-scheer Mar 18, 2021
6906a8c
Change lib.apollo.dev to specs.apollo.dev
martijnwalraven Mar 31, 2021
247fb10
Remove unnecessary assignment from `MultiMap`
martijnwalraven Mar 31, 2021
bc31b88
Only filter out directives with the unprefixed feature name
martijnwalraven Mar 31, 2021
19ae2f6
Address typos and enforce specifying assertion messages
martijnwalraven Mar 31, 2021
36cdac4
Avoid unnecessary check for undefined
martijnwalraven Mar 31, 2021
5b30ba8
Rename Endpoint -> Graph and serviceName -> graphName
martijnwalraven Mar 31, 2021
6abb7d4
Merge branch 'release-0.26.0' into typescript-redux
trevor-scheer Mar 31, 2021
466c6e1
Update the thing that TS didn't catch for me :sadface:
trevor-scheer Mar 31, 2021
f9e4cf7
(optionally) REVERT ME: cachebuster
trevor-scheer Mar 31, 2021
9db6aa9
Update changelogs
trevor-scheer Mar 31, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
362 changes: 158 additions & 204 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion codegen.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
overwrite: true
schema: "https://us-central1-mdg-services.cloudfunctions.net:443/cloudconfig-staging/"
documents:
- gateway-js/src/loadCsdlFromStorage.ts
- gateway-js/src/loadSupergraphSdlFromStorage.ts
generates:
gateway-js/src/__generated__/graphqlTypes.ts:
plugins:
Expand Down
1 change: 1 addition & 0 deletions federation-integration-testsuite-js/src/matchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import './toCallService';
import './toHaveBeenCalledBefore';
import './toHaveFetched';
import './toMatchAST';
import './toMatchQueryPlan';
45 changes: 45 additions & 0 deletions federation-js/src/__tests__/joinSpec.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { fixtures } from 'apollo-federation-integration-testsuite';
import { getJoins } from "../joinSpec";

const questionableNamesRemap = {
accounts: 'ServiceA',
books: 'serviceA',
documents: 'servicea_2',
inventory: 'servicea_2_',
product: '9product*!',
reviews: 'reviews_9',
};

const fixturesWithQuestionableServiceNames = fixtures.map((service) => ({
...service,
name: questionableNamesRemap[service.name],
}));

describe('join__Graph enum', () => {
it('correctly uniquifies and sanitizes service names', () => {
const { sanitizedServiceNames } = getJoins(
fixturesWithQuestionableServiceNames,
);

/**
* Expectations
* 1. Non-Alphanumeric characters are replaced with _ (9product*!)
* 2. Numeric first characters are prefixed with _ (9product*!)
* 3. Names ending in an underscore followed by numbers `_\d+` are suffixed with _ (reviews_9, servicea_2)
* 4. Names are uppercased (all)
* 5. After transformations 1-4, duplicates are suffixed with _{n} where {n} is number of times we've seen the dupe (ServiceA + serviceA, servicea_2 + servicea_2_)
*
* Miscellany
* (serviceA) tests the edge case of colliding with a name we generated
* (servicea_2_) tests a collision against (documents) post-transformation
*/
expect(sanitizedServiceNames).toMatchObject({
'9product*!': '_9PRODUCT__',
ServiceA: 'SERVICEA',
reviews_9: 'REVIEWS_9_',
serviceA: 'SERVICEA_2',
servicea_2: 'SERVICEA_2_',
servicea_2_: 'SERVICEA_2__2',
});
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -689,15 +689,15 @@ describe('composition of value types', () => {
]);

assertCompositionSuccess(compositionResult);
const { schema, composedSdl } = compositionResult;
const { schema, supergraphSdl } = compositionResult;
expect(
(schema.getType('Product') as GraphQLObjectType).getInterfaces(),
).toHaveLength(2);

expect(printSchema(schema)).toContain(
'type Product implements Named & Node',
);
expect(composedSdl).toContain('type Product implements Named & Node');
expect(supergraphSdl).toContain('type Product implements Named & Node');
});
});

Expand Down
5 changes: 3 additions & 2 deletions federation-js/src/composition/compose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import {
} from './types';
import { validateSDL } from 'graphql/validation/validate';
import { compositionRules } from './rules';
import { printComposedSdl } from '../service/printComposedSdl';
import { printSupergraphSdl } from '../service/printSupergraphSdl';

const EmptyQueryDefinition = {
kind: Kind.OBJECT_TYPE_DEFINITION,
Expand Down Expand Up @@ -156,6 +156,7 @@ export function buildMapsFromServiceList(serviceList: ServiceDefinition[]) {
if (
definition.kind === Kind.OBJECT_TYPE_DEFINITION ||
definition.kind === Kind.OBJECT_TYPE_EXTENSION
// || definition.kind === Kind.INTERFACE_TYPE_DEFINITION
) {
const typeName = definition.name.value;

Expand Down Expand Up @@ -660,7 +661,7 @@ export function composeServices(services: ServiceDefinition[]): CompositionResul
} else {
return {
schema,
composedSdl: printComposedSdl(schema, services),
supergraphSdl: printSupergraphSdl(schema, services),
};
}
}
8 changes: 4 additions & 4 deletions federation-js/src/composition/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,16 +607,16 @@ export type CompositionResult = CompositionFailure | CompositionSuccess;
// Yes, it's a bit awkward that we still return a schema when errors occur.
// This is old behavior that I'm choosing not to modify for now.
export interface CompositionFailure {
/** @deprecated Use composedSdl instead */
/** @deprecated Use supergraphSdl instead */
schema: GraphQLSchema;
errors: GraphQLError[];
composedSdl?: undefined;
supergraphSdl?: undefined;
}

export interface CompositionSuccess {
/** @deprecated Use composedSdl instead */
/** @deprecated Use supergraphSdl instead */
schema: GraphQLSchema;
composedSdl: string;
supergraphSdl: string;
errors?: undefined;
}

Expand Down
17 changes: 17 additions & 0 deletions federation-js/src/coreSpec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {
GraphQLDirective,
DirectiveLocation,
GraphQLNonNull,
GraphQLString,
} from 'graphql';

export const CoreDirective = new GraphQLDirective({
name: 'core',
locations: [DirectiveLocation.SCHEMA],
args: {
feature: {
type: new GraphQLNonNull(GraphQLString),
},
},
isRepeatable: true,
});
97 changes: 0 additions & 97 deletions federation-js/src/csdlDirectives.ts

This file was deleted.

6 changes: 3 additions & 3 deletions federation-js/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const KeyDirective = new GraphQLDirective({
locations: [DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE],
args: {
fields: {
type: GraphQLNonNull(GraphQLString),
type: new GraphQLNonNull(GraphQLString),
},
},
});
Expand All @@ -46,7 +46,7 @@ export const RequiresDirective = new GraphQLDirective({
locations: [DirectiveLocation.FIELD_DEFINITION],
args: {
fields: {
type: GraphQLNonNull(GraphQLString),
type: new GraphQLNonNull(GraphQLString),
},
},
});
Expand All @@ -56,7 +56,7 @@ export const ProvidesDirective = new GraphQLDirective({
locations: [DirectiveLocation.FIELD_DEFINITION],
args: {
fields: {
type: GraphQLNonNull(GraphQLString),
type: new GraphQLNonNull(GraphQLString),
},
},
});
Expand Down