Skip to content

federation: fix warning for mismatched unnamed @external #4392

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion packages/apollo-federation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

> The changes noted within this `vNEXT` section have not been released yet. New PRs and commits which introduce changes should include an entry in this `vNEXT` section as part of their development. When a release is being prepared, a new header will be (manually) created below and the appropriate changes within that release will be moved into the new section.

- _Nothing yet! Stay tuned!_
- Fix warning for non-matching `@external` types when the declaration's type is non-null or a list [PR #4392](https://github.com/apollographql/apollo-server/pull/4392)

## v0.18.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ describe('validateExternalDirectivesOnSchema', () => {
it('warns when the type of an @external field doesnt match the base', () => {
const serviceA = {
typeDefs: gql`
type Product @key(fields: "sku") {
type Product @key(fields: "sku skew") {
sku: String!
skew: String
upc: String!
}
`,
Expand All @@ -21,7 +22,8 @@ describe('validateExternalDirectivesOnSchema', () => {
typeDefs: gql`
extend type Product {
sku: String @external
price: Int! @requires(fields: "sku")
skew: String! @external
price: Int! @requires(fields: "sku skew")
}
`,
name: 'serviceB',
Expand All @@ -36,6 +38,10 @@ describe('validateExternalDirectivesOnSchema', () => {
"code": "EXTERNAL_TYPE_MISMATCH",
"message": "[serviceB] Product.sku -> Type \`String\` does not match the type of the original field in serviceA (\`String!\`)",
},
Object {
"code": "EXTERNAL_TYPE_MISMATCH",
"message": "[serviceB] Product.skew -> Type \`String!\` does not match the type of the original field in serviceA (\`String\`)",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the code change, this says undefined instead of String!

},
]
`);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObjectType, typeFromAST, isEqualType, GraphQLError } from 'graphql';
import { isObjectType, typeFromAST, isEqualType, GraphQLError, GraphQLType } from 'graphql';
import { logServiceAndType, errorWithCode, getFederationMetadata } from '../../utils';
import { PostCompositionValidator } from '.';

Expand Down Expand Up @@ -34,7 +34,7 @@ export const externalTypeMismatch: PostCompositionValidator = ({ schema }) => {
const externalFieldType = typeFromAST(
schema,
externalField.type as any,
);
) as GraphQLType;

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