Skip to content

Commit a6347aa

Browse files
committed
Remove EXTERNAL_MISSING_ON_BASE error
1 parent 1ab7efa commit a6347aa

File tree

6 files changed

+32
-19
lines changed

6 files changed

+32
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { graphqlErrorSerializer } from '../../../../snapshotSerializers';
66
expect.addSnapshotSerializer(graphqlErrorSerializer);
77

88
describe('externalMissingOnBase', () => {
9-
it('warns when an @external field does not have a matching field on the base type', () => {
9+
it.skip('warns when an @external field does not have a matching field on the base type', () => {
1010
const serviceA = {
1111
typeDefs: gql`
1212
type Product @key(fields: "sku") {

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ export const externalMissingOnBase: PostCompositionValidator = ({ schema }) => {
4141

4242
// if the field has a serviceName, then it wasn't defined by the
4343
// service that owns the type
44-
if (
45-
matchingBaseField.federation &&
46-
matchingBaseField.federation.serviceName
47-
) {
48-
errors.push(
49-
errorWithCode(
50-
'EXTERNAL_MISSING_ON_BASE',
51-
logServiceAndType(serviceName, typeName, externalFieldName) +
52-
`marked @external but ${externalFieldName} was defined in ${matchingBaseField.federation.serviceName}, not in the service that owns ${typeName} (${namedType.federation.serviceName})`,
53-
),
54-
);
55-
}
44+
// if (
45+
// matchingBaseField.federation &&
46+
// matchingBaseField.federation.serviceName
47+
// ) {
48+
// errors.push(
49+
// errorWithCode(
50+
// 'EXTERNAL_MISSING_ON_BASE',
51+
// logServiceAndType(serviceName, typeName, externalFieldName) +
52+
// `marked @external but ${externalFieldName} was defined in ${matchingBaseField.federation.serviceName}, not in the service that owns ${typeName} (${namedType.federation.serviceName})`,
53+
// ),
54+
// );
55+
// }
5656
}
5757
}
5858
}

packages/apollo-gateway/src/FieldSet.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
SelectionNode,
99
SelectionSetNode,
1010
GraphQLObjectType,
11+
isObjectType,
1112
} from 'graphql';
1213
import { getResponseName } from './utilities/graphql';
1314

@@ -41,7 +42,11 @@ export function printFields(fields?: FieldSet) {
4142
export function matchesField(field: Field) {
4243
// TODO: Compare parent type and arguments
4344
return (otherField: Field) => {
44-
return field.fieldDef.name === otherField.fieldDef.name;
45+
return (
46+
field.fieldDef.name === otherField.fieldDef.name &&
47+
isObjectType(field.scope.parentType) &&
48+
otherField.scope.possibleTypes.includes(field.scope.parentType)
49+
);
4550
};
4651
}
4752

packages/apollo-gateway/src/__tests__/__fixtures__/schemas/product.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const typeDefs = gql`
2929
name: String
3030
price: String
3131
details: ProductDetails
32+
manufacturer: String
3233
}
3334
3435
interface ProductDetails {
@@ -53,6 +54,7 @@ export const typeDefs = gql`
5354
brand: Brand
5455
metadata: [MetadataOrError]
5556
details: ProductDetailsFurniture
57+
manufacturer: String
5658
}
5759
5860
extend type Book implements Product @key(fields: "isbn") {
@@ -64,6 +66,7 @@ export const typeDefs = gql`
6466
name(delimeter: String = " "): String @requires(fields: "title year")
6567
price: String
6668
details: ProductDetailsBook
69+
manufacturer: String
6770
}
6871
6972
interface Vehicle {

packages/apollo-gateway/src/__tests__/__fixtures__/schemas/reviews.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const typeDefs = gql`
1414
id: ID!
1515
body(format: Boolean = false): String
1616
author: User @provides(fields: "username")
17-
product: Product
17+
product: Product @provides(fields: "manufacturer")
1818
metadata: [MetadataOrError]
1919
}
2020
@@ -36,16 +36,18 @@ export const typeDefs = gql`
3636
goodAddress: Boolean @requires(fields: "metadata { address }")
3737
}
3838
39-
extend interface Product {
39+
extend interface Product @key(fields:"upc") {
4040
reviews: [Review]
4141
}
4242
4343
extend type Furniture implements Product @key(fields: "upc") {
44+
manufacturer: String @external
4445
upc: String! @external
4546
reviews: [Review]
4647
}
4748
4849
extend type Book implements Product @key(fields: "isbn") {
50+
manufacturer: String @external
4951
isbn: String! @external
5052
reviews: [Review]
5153
similarBooks: [Book]! @external
@@ -98,14 +100,14 @@ const reviews = [
98100
{
99101
id: '1',
100102
authorID: '1',
101-
product: { __typename: 'Furniture', upc: '1' },
103+
product: { __typename: 'Furniture', upc: '1', manufacturer:'factoryA' },
102104
body: 'Love it!',
103105
metadata: [{ code: 418, message: "I'm a teapot" }],
104106
},
105107
{
106108
id: '2',
107109
authorID: '1',
108-
product: { __typename: 'Furniture', upc: '2' },
110+
product: { __typename: 'Furniture', upc: '2', manufacturer:'factoryB' },
109111
body: 'Too expensive.',
110112
},
111113
{

packages/apollo-gateway/src/buildQueryPlan.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ function splitSubfields(
331331
parentGroup.providedFields.some(matchesField(requiredField)),
332332
)
333333
) {
334-
if (owningService === parentGroup.serviceName) {
334+
if (
335+
owningService === parentGroup.serviceName ||
336+
parentGroup.providedFields.some(matchesField(field))
337+
) {
335338
return parentGroup;
336339
} else {
337340
return parentGroup.dependentGroupForService(

0 commit comments

Comments
 (0)