Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/small-books-shave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'hive': patch
---

Fix issue where wrong subgraph is shown as the owner of a schema coordinate/field.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ describe('extractSuperGraphInformation', () => {
reviews,
],
Product.dimensions => [
inventory,
products,
],
Product.delivery => [
inventory,
Expand Down Expand Up @@ -543,3 +543,91 @@ test('subgraph ownership for external fields is correct', () => {
'b',
]);
});

test('subgraph ownership picks first non external "join__field" annotation', () => {
// See Product.weight within the schema
// B is picked as the owner even though it is external
const supergraphSdl = /* GraphQL */ `
schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(url: "https://specs.apollo.dev/join/v0.3", for: EXECUTION) {
query: Query
}

directive @join__enumValue(graph: join__Graph!) repeatable on ENUM_VALUE

directive @join__graph(name: String!, url: String!) on ENUM_VALUE

directive @join__field(
graph: join__Graph
requires: join__FieldSet
provides: join__FieldSet
type: String
external: Boolean
override: String
usedOverridden: Boolean
) repeatable on FIELD_DEFINITION | INPUT_FIELD_DEFINITION

directive @join__implements(
graph: join__Graph!
interface: String!
) repeatable on OBJECT | INTERFACE

directive @join__type(
graph: join__Graph!
key: join__FieldSet
extension: Boolean! = false
resolvable: Boolean! = true
isInterfaceObject: Boolean! = false
) repeatable on OBJECT | INTERFACE | UNION | ENUM | INPUT_OBJECT | SCALAR

directive @join__unionMember(graph: join__Graph!, member: String!) repeatable on UNION

scalar join__FieldSet

directive @link(
url: String
as: String
for: link__Purpose
import: [link__Import]
) repeatable on SCHEMA

scalar link__Import

enum link__Purpose {
SECURITY
EXECUTION
}

enum join__Graph {
A @join__graph(name: "a", url: "")
B @join__graph(name: "b", url: "")
}

type Product @join__type(graph: A, key: "id") @join__type(graph: B, key: "id") {
id: ID!
# THIS IS THE RELEVANT FIELD FOR THIS TEST
weight: ProductWeight! @join__field(graph: B, external: true) @join__field(graph: A)
shippingCosts: Int! @join__field(graph: B, requires: "weight{id}")
}

type ProductWeight @join__type(graph: A) @join__type(graph: B) {
id: ID! @join__field(graph: A) @join__field(graph: B, external: true)
weight: Int! @join__field(graph: A)
}

type Query @join__type(graph: A) @join__type(graph: B) {
a: Product! @join__field(graph: A)
g: ProductWeight! @join__field(graph: A)
c: Product! @join__field(graph: B)
}
`;

const supergraphInfo = extractSuperGraphInformation(parse(supergraphSdl!));
expect(supergraphInfo.schemaCoordinateServicesMappings.get('Product.weight')).toEqual(['a']);
expect(supergraphInfo.schemaCoordinateServicesMappings.get('ProductWeight.id')).toEqual(['a']);
expect(supergraphInfo.schemaCoordinateServicesMappings.get('ProductWeight')).toEqual(['a', 'b']);
expect(supergraphInfo.schemaCoordinateServicesMappings.get('Product.shippingCosts')).toEqual([
'b',
]);
});
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ export const extractSuperGraphInformation = traceInlineSync(
directive.name.value === joinFieldDirectiveName &&
!directive.arguments?.find(
arg =>
arg.name.value === 'usedOverridden' &&
arg.value.kind === Kind.BOOLEAN &&
arg.value.value === true,
(arg.name.value === 'usedOverridden' &&
arg.value.kind === Kind.BOOLEAN &&
arg.value.value === true) ||
(arg.name.value === 'external' &&
arg.value.kind === Kind.BOOLEAN &&
arg.value.value === true),
Comment on lines +95 to +97
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before we would pick a directive even though it is external

),
);

const graphArg = joinField?.arguments?.find(arg => arg.name.value === 'graph');

if (graphArg === undefined) {
Expand Down
Loading