Skip to content

Commit a7412d1

Browse files
committed
federation: fix warning for mismatched unnamed @external
Some TypeScript weirdness means we were getting the GraphQLNamedType overload of typeFromAST, which meant we were calling `.name` on it, which is undefined for non-null and list types.
1 parent 9873ba4 commit a7412d1

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

packages/apollo-federation/src/composition/validate/postComposition/__tests__/externalTypeMismatch.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ describe('validateExternalDirectivesOnSchema', () => {
99
it('warns when the type of an @external field doesnt match the base', () => {
1010
const serviceA = {
1111
typeDefs: gql`
12-
type Product @key(fields: "sku") {
12+
type Product @key(fields: "sku skew") {
1313
sku: String!
14+
skew: String
1415
upc: String!
1516
}
1617
`,
@@ -21,7 +22,8 @@ describe('validateExternalDirectivesOnSchema', () => {
2122
typeDefs: gql`
2223
extend type Product {
2324
sku: String @external
24-
price: Int! @requires(fields: "sku")
25+
skew: String! @external
26+
price: Int! @requires(fields: "sku skew")
2527
}
2628
`,
2729
name: 'serviceB',
@@ -36,6 +38,10 @@ describe('validateExternalDirectivesOnSchema', () => {
3638
"code": "EXTERNAL_TYPE_MISMATCH",
3739
"message": "[serviceB] Product.sku -> Type \`String\` does not match the type of the original field in serviceA (\`String!\`)",
3840
},
41+
Object {
42+
"code": "EXTERNAL_TYPE_MISMATCH",
43+
"message": "[serviceB] Product.skew -> Type \`String!\` does not match the type of the original field in serviceA (\`String\`)",
44+
},
3945
]
4046
`);
4147
});

packages/apollo-federation/src/composition/validate/postComposition/externalTypeMismatch.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isObjectType, typeFromAST, isEqualType, GraphQLError } from 'graphql';
1+
import { isObjectType, typeFromAST, isEqualType, GraphQLError, GraphQLType } from 'graphql';
22
import { logServiceAndType, errorWithCode, getFederationMetadata } from '../../utils';
33
import { PostCompositionValidator } from '.';
44

@@ -34,7 +34,7 @@ export const externalTypeMismatch: PostCompositionValidator = ({ schema }) => {
3434
const externalFieldType = typeFromAST(
3535
schema,
3636
externalField.type as any,
37-
);
37+
) as GraphQLType;
3838

3939
if (!externalFieldType) {
4040
errors.push(
@@ -52,7 +52,7 @@ export const externalTypeMismatch: PostCompositionValidator = ({ schema }) => {
5252
errorWithCode(
5353
'EXTERNAL_TYPE_MISMATCH',
5454
logServiceAndType(serviceName, typeName, externalFieldName) +
55-
`Type \`${externalFieldType.name}\` does not match the type of the original field in ${typeFederationMetadata.serviceName} (\`${matchingBaseField.type}\`)`,
55+
`Type \`${externalFieldType}\` does not match the type of the original field in ${typeFederationMetadata.serviceName} (\`${matchingBaseField.type}\`)`,
5656
),
5757
);
5858
}

0 commit comments

Comments
 (0)