diff --git a/packages/apollo-federation/src/composition/rules.ts b/packages/apollo-federation/src/composition/rules.ts index fbbff121fa6..012ee569ed9 100644 --- a/packages/apollo-federation/src/composition/rules.ts +++ b/packages/apollo-federation/src/composition/rules.ts @@ -1,27 +1,58 @@ import { specifiedSDLRules } from 'graphql/validation/specifiedRules'; +/** + * Note that, because this module has overlapping names from the two modules + * (graphql-js and our own, local validation rules) which we are importing from + * we intentionally are very explicit about the suffixes of imported members + * here, in order to make the intention clear. + * + * First, we'll import validation rules from graphql-js which we'll omit and + * replace with our own validation rules. Note that we'll take alias each of + * these to the same name with 'FromGraphqlJs' suffixes. + */ import { - UniqueTypeNamesWithFields, - MatchingEnums, - PossibleTypeExtensions, - UniqueFieldDefinitionNames, - UniqueUnionTypes, -} from './validate/sdl'; + UniqueDirectivesPerLocation as UniqueDirectivesPerLocationFromGraphqlJs, +} from 'graphql/validation/rules/UniqueDirectivesPerLocation'; +import { + UniqueTypeNames as UniqueTypeNamesFromGraphqlJs, +} from 'graphql/validation/rules/UniqueTypeNames'; +import { + UniqueEnumValueNames as UniqueEnumValueNamesFromGraphqlJs, +} from 'graphql/validation/rules/UniqueEnumValueNames'; +import { + PossibleTypeExtensions as PossibleTypeExtensionsFromGraphqlJs, +} from 'graphql/validation/rules/PossibleTypeExtensions'; +import { + UniqueFieldDefinitionNames as UniqueFieldDefinitionNamesFromGraphqlJs, +} from 'graphql/validation/rules/UniqueFieldDefinitionNames'; + +/** + * Then, we'll import our own validation rules to take the place of those that + * we'll be customizing, taking care to alias them all to the same name with + * "FromComposition" suffixes. + */ +import { + UniqueTypeNamesWithFields as UniqueTypeNamesWithFieldsFromComposition, + MatchingEnums as MatchingEnumsFromComposition, + PossibleTypeExtensions as PossibleTypeExtensionsFromComposition, + UniqueFieldDefinitionNames as UniqueFieldDefinitionsNamesFromComposition, + UniqueUnionTypes as UniqueUnionTypesFromComposition, + } from './validate/sdl'; const omit = [ - 'UniqueDirectivesPerLocation', - 'UniqueTypeNames', - 'UniqueEnumValueNames', - 'PossibleTypeExtensions', - 'UniqueFieldDefinitionNames', + UniqueDirectivesPerLocationFromGraphqlJs, + UniqueTypeNamesFromGraphqlJs, + UniqueEnumValueNamesFromGraphqlJs, + PossibleTypeExtensionsFromGraphqlJs, + UniqueFieldDefinitionNamesFromGraphqlJs, ]; export const compositionRules = specifiedSDLRules - .filter(rule => !omit.includes(rule.name)) + .filter(rule => !omit.includes(rule)) .concat([ - UniqueFieldDefinitionNames, - UniqueTypeNamesWithFields, - MatchingEnums, - UniqueUnionTypes, - PossibleTypeExtensions, + UniqueFieldDefinitionsNamesFromComposition, + UniqueTypeNamesWithFieldsFromComposition, + MatchingEnumsFromComposition, + UniqueUnionTypesFromComposition, + PossibleTypeExtensionsFromComposition, ]);