Skip to content

Commit

Permalink
Move snapshot serializers and matchers to federaton-integration-tests…
Browse files Browse the repository at this point in the history
…uite

Snapshot serializers were duplicated in `@apollo/federation` and `@apollo/gateway`. This moves both the snapshot serializers and the matchers to `apollo-federaton-integration-testsuite` (we may want to rename that package).

I temporarily disabled the option for the gateway to include the pretty printed query plan under `__queryPlanExperimental` (which is used to show the query plan in the Playground we ship with Apollo Server), because this lead to a circular dependency between `@apollo/gateway` and apollo-federaton-integration-testsuite`. We should either solve that or switch Playground to use the JSON serialization format for the query plan.
  • Loading branch information
martijnwalraven committed Feb 4, 2021
1 parent 22395b6 commit 68ef9d6
Show file tree
Hide file tree
Showing 69 changed files with 84 additions and 143 deletions.
4 changes: 4 additions & 0 deletions federation-integration-testsuite-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export * from './matchers';
export * from './snapshotSerializers';
export * from './fixtures';

export { prettyFormatQueryPlan } from './prettyFormatQueryPlan';
4 changes: 4 additions & 0 deletions federation-integration-testsuite-js/src/matchers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import './toCallService';
import './toHaveBeenCalledBefore';
import './toHaveFetched';
import './toMatchAST';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { QueryPlan } from '@apollo/gateway';
import { PlanNode } from '../../QueryPlan';
import astSerializer from '../../snapshotSerializers/astSerializer';
import queryPlanSerializer from '../../snapshotSerializers/queryPlanSerializer';
import { QueryPlan, PlanNode } from '@apollo/gateway';
import astSerializer from '../snapshotSerializers/astSerializer';
import queryPlanSerializer from '../snapshotSerializers/queryPlanSerializer';
const prettyFormat = require('pretty-format');

declare global {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ function prepareHttpOptions(requestUrl: string, requestOpts: RequestInit): Reque
const headers = new Headers();
headers.set('Content-Type', 'application/json');
if (requestOpts.headers) {
for (let name in requestOpts.headers) {
headers.set(name, requestOpts.headers[name]);
for (const [name, value] of new Headers(requestOpts.headers)) {
headers.set(name, value);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { QueryPlan } from '@apollo/gateway';
import prettyFormat from 'pretty-format';
import { astSerializer, queryPlanSerializer } from './snapshotSerializers';

export function prettyFormatQueryPlan(queryPlan: QueryPlan) {
return prettyFormat(queryPlan, {
plugins: [queryPlanSerializer, astSerializer],
});
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ASTNode, print, Kind, visit } from 'graphql';
import { Plugin, Config, Refs } from 'pretty-format';
import { QueryPlanSelectionNode, QueryPlanInlineFragmentNode } from '../QueryPlan';
import { QueryPlanSelectionNode, QueryPlanInlineFragmentNode } from '@apollo/gateway';
import { SelectionNode as GraphQLJSSelectionNode } from 'graphql';

export default {
Expand All @@ -18,7 +18,6 @@ export default {
): string {
return print(remapInlineFragmentNodes(value))
.trim()
.replace(/\n\n/g, '\n')
.replace(/\n/g, '\n' + indentation);
},
} as Plugin;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export { default as astSerializer } from './astSerializer';
export { default as selectionSetSerializer } from './selectionSetSerializer';
export { default as typeSerializer } from './typeSerializer';
export { default as graphqlErrorSerializer } from './graphqlErrorSerializer';
export { default as queryPlanSerializer } from './queryPlanSerializer';

declare global {
namespace jest {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Config, Plugin, Refs } from 'pretty-format';
import { PlanNode, QueryPlan } from '../QueryPlan';
import { PlanNode, QueryPlan } from '@apollo/gateway';
import { parse, Kind, visit, DocumentNode } from 'graphql';

export default {
Expand Down
6 changes: 3 additions & 3 deletions federation-integration-testsuite-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"noImplicitAny": false,
"strictNullChecks": false,
"types": ["node", "jest"]
},
"include": ["src/**/*"],
"exclude": ["**/__tests__"],
"references": []
"references": [
{ "path": "../gateway-js" }
]
}
2 changes: 1 addition & 1 deletion federation-js/src/composition/__tests__/compose.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
astSerializer,
typeSerializer,
selectionSetSerializer,
} from '../../snapshotSerializers';
} from 'apollo-federation-integration-testsuite';
import { normalizeTypeDefs } from '../normalize';
import {
assertCompositionFailure,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
astSerializer,
typeSerializer,
graphqlErrorSerializer,
} from '../../snapshotSerializers';
} from 'apollo-federation-integration-testsuite';
import {
assertCompositionFailure,
assertCompositionSuccess,
Expand Down
2 changes: 1 addition & 1 deletion federation-js/src/composition/__tests__/normalize.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
normalizeTypeDefs,
stripCommonPrimitives,
} from '../normalize';
import { astSerializer } from '../../snapshotSerializers';
import { astSerializer } from 'apollo-federation-integration-testsuite';
import { specifiedDirectives } from 'graphql';

expect.addSnapshotSerializer(astSerializer);
Expand Down
2 changes: 1 addition & 1 deletion federation-js/src/composition/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import deepFreeze from 'deep-freeze';
import { stripExternalFieldsFromTypeDefs } from '../utils';
import { astSerializer } from '../../snapshotSerializers';
import { astSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(astSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { executableDirectivesIdentical } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { executableDirectivesInAllServices } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { externalMissingOnBase as validateExternalMissingOnBase } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { externalTypeMismatch as validateExternalTypeMismatch } from '../';
import { composeServices } from '../../../compose';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { externalUnused as validateExternalUnused } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { keyFieldsMissingOnBase as validateKeyFieldsMissingOnBase } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
import { assertCompositionSuccess } from '../../../utils';

expect.addSnapshotSerializer(graphqlErrorSerializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { keyFieldsSelectInvalidType as validateKeyFieldsSelectInvalidType } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
import { assertCompositionSuccess } from '../../../utils';

expect.addSnapshotSerializer(graphqlErrorSerializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { keysMatchBaseService as validateKeysMatchBaseService } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
import { assertCompositionSuccess } from '../../../utils';

expect.addSnapshotSerializer(graphqlErrorSerializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { providesFieldsMissingExternal as validateProdivesFieldsMissingExternal } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
import { assertCompositionSuccess } from '../../../utils';

expect.addSnapshotSerializer(graphqlErrorSerializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { providesFieldsSelectInvalidType as validateprovidesFieldsSelectInvalidType } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';
import { assertCompositionSuccess } from '../../../utils';

expect.addSnapshotSerializer(graphqlErrorSerializer);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { providesNotOnEntity as validateProvidesNotOnEntity } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { requiresFieldsMissingExternal as validateRequiresFieldsMissingExternal } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { composeServices } from '../../../compose';
import { requiresFieldsMissingOnBase as validateRequiresFieldsMissingOnBase } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag';
import { duplicateEnumOrScalar as validateDuplicateEnumOrScalar } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag';
import { duplicateEnumValue as validateDuplicateEnumValue } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag';
import { externalUsedOnBase as validateExternalUsedOnBase } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag';
import { keyFieldsMissingExternal as validateKeyFieldsMissingExternal } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag';
import { requiresUsedOnBase as validateRequiresUsedOnBase } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag';
import { reservedFieldUsed as validateReservedFieldUsed } from '..';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import gql from 'graphql-tag';
import { rootFieldUsed as validateRootFieldUsed } from '../';
import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
import { graphqlErrorSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(graphqlErrorSerializer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
astSerializer,
typeSerializer,
selectionSetSerializer,
} from '../../../../snapshotSerializers';
} from 'apollo-federation-integration-testsuite';
import { normalizeTypeDefs } from '../../../normalize';
import federationDirectives from '../../../../directives';
import { ServiceDefinition } from '../../../types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import gql from 'graphql-tag';
import {
typeSerializer,
graphqlErrorSerializer,
} from '../../../../snapshotSerializers';
} from 'apollo-federation-integration-testsuite';
import { UniqueUnionTypes } from '..';
import { ServiceDefinition } from '../../../types';
import { buildMapsFromServiceList } from '../../../compose';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { buildMapsFromServiceList } from '../../../compose';
import {
typeSerializer,
graphqlErrorSerializer,
} from '../../../../snapshotSerializers';
} from 'apollo-federation-integration-testsuite';
import federationDirectives from '../../../../directives';
import { ServiceDefinition } from '../../../types';
import { PossibleTypeExtensions } from '../possibleTypeExtensions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
} from 'graphql';
import { validateSDL } from 'graphql/validation/validate';
import gql from 'graphql-tag';
import { typeSerializer } from '../../../../snapshotSerializers';
import { typeSerializer } from 'apollo-federation-integration-testsuite';
import { buildMapsFromServiceList } from '../../../compose';
import federationDirectives from '../../../../directives';
import { UniqueFieldDefinitionNames } from '..';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import gql from 'graphql-tag';
import {
typeSerializer,
graphqlErrorSerializer,
} from '../../../../snapshotSerializers';
} from 'apollo-federation-integration-testsuite';
import federationDirectives from '../../../../directives';
import { UniqueTypeNamesWithFields } from '..';
import { ServiceDefinition } from '../../../types';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import gql from 'graphql-tag';
import { Kind, graphql, DocumentNode, execute } from 'graphql';
import { buildFederatedSchema } from '../buildFederatedSchema';
import { typeSerializer } from '../../snapshotSerializers';
import { typeSerializer } from 'apollo-federation-integration-testsuite';

expect.addSnapshotSerializer(typeSerializer);

Expand Down
21 changes: 0 additions & 21 deletions federation-js/src/snapshotSerializers/astSerializer.ts

This file was deleted.

4 changes: 1 addition & 3 deletions federation-js/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@
},
"include": ["src/**/*"],
"exclude": ["**/__tests__"],
"references": [
{ "path": "../federation-integration-testsuite-js" }
]
"references": []
}
1 change: 1 addition & 0 deletions federation-js/tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"include": ["**/__tests__/**/*"],
"references": [
{ "path": "./" },
{ "path": "../federation-integration-testsuite-js" },
]
}
Loading

0 comments on commit 68ef9d6

Please sign in to comment.