Skip to content
Draft
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
152 changes: 133 additions & 19 deletions __tests__/composition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,120 @@
`);
});

test(`extend type causes additional @join__type(extension: true)`, () => {
const result = composeServices([
{
name: "a",
typeDefs: parse(/* GraphQL */ `
extend schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key"]
)

type Query {
a: String
}

type MediaReference @key(fields: "assetId") {
assetId: String!
}
`),
},
{
name: "b",
typeDefs: parse(/* GraphQL */ `
extend schema
@link(url: "https://specs.apollo.dev/link/v1.0")
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key"]
)

type Query {
b: String
}

type MediaReference @key(fields: "assetId") {
assetId: String!
}
extend type MediaReference @key(fields: "assetId") {
media: String
}
`),
},
]);

expect(result.errors).toEqual(undefined);
expect(result.supergraphSdl).toContain(

Check failure on line 297 in __tests__/composition.spec.ts

View workflow job for this annotation

GitHub Actions / Test

__tests__/composition.spec.ts > 'guild' > extend type causes additional @join__type(extension: true)

AssertionError: expected '\n\n schema\n @link(url: "https…' to contain '@join__type(graph: B, key: "assetId",…' - Expected + Received - @join__type(graph: B, key: "assetId", extension: true) + + + 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` features provide metadata necessary to securely resolve fields. + """ + SECURITY + + """ + `EXECUTION` features provide metadata necessary for operation execution. + """ + EXECUTION + } + + + + + + + + + enum join__Graph { + A @join__graph(name: "a", url: "") + B @join__graph(name: "b", url: "") + } + + type Query @join__type(graph: A) @join__type(graph: B) { + a: String @join__field(graph: A) + b: String @join__field(graph: B) + } + + type MediaReference @join__type(graph: A, key: "assetId") @join__type(graph: B, key: "assetId") @join__type(graph: B, key: "assetId") { + assetId: String! + media: String @join__field(graph: B) + } + ❯ __tests__/composition.spec.ts:297:34
`@join__type(graph: B, key: "assetId", extension: true)`,
);
});

test(`@join__field(external: true) missing because of ???`, () => {
let result = composeServices([
{
name: "a",
typeDefs: parse(/* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: [
"@key"
"@requires"
"@external"
"@shareable"
"@extends"
]
)

type Query {
a: String
}

type Order @extends @shareable @key(fields: "id") {
id: ID! @external
id2: ID @external
orderProgress: String! @requires(fields: "id2")
}
`),
},
{
name: "b",
typeDefs: parse(/* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
)

type Query {
b: String
}

type Order @key(fields: "id") @key(fields: "id2") @shareable {
id: ID!
id2: ID
countryCode: String!
}
`),
},
]);

assertCompositionSuccess(result);

console.log(result.supergraphSdl);

const line = result.supergraphSdl
.split("\n")
.find((line) => line.includes("id2: ID"));
const [, remainder] = line!.split("id2: ID");

expect(remainder).toContain("@join__field(graph: A, external: true)");

Check failure on line 361 in __tests__/composition.spec.ts

View workflow job for this annotation

GitHub Actions / Test

__tests__/composition.spec.ts > 'guild' > @join__field(external: true) missing because of ???

AssertionError: expected '' to contain '@join__field(graph: A, external: true)' - Expected + Received - @join__field(graph: A, external: true) ❯ __tests__/composition.spec.ts:361:23
expect(remainder).toContain("@join__field(graph: B)");
});

test("@join__field(external: true) when field is overridden", () => {
let result = composeServices([
{
Expand Down Expand Up @@ -7382,25 +7496,25 @@
typeDefs: parse(/* GraphQL */ `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@shareable"]
)
type Note @key(fields: "id") @shareable {
id: ID!
name: String
author: User
}
type User @key(fields: "id") {
id: ID!
name: String
id: ID!
name: String
}
type PrivateNote @key(fields: "id") @shareable {
id: ID!
note: Note
}
type Query {
note: Note @shareable
privateNote: PrivateNote @shareable
type PrivateNote @key(fields: "id") @shareable {
id: ID!
note: Note
}
type Query {
note: Note @shareable
privateNote: PrivateNote @shareable
}
`),
},
Expand All @@ -7425,9 +7539,9 @@
result = api.composeServices([
{
name: "foo",
typeDefs: parse(/* GraphQL */ `
typeDefs: parse(/* GraphQL */ `
extend schema
@link(
@link(
url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@external", "@provides", "@shareable"]
)
Expand All @@ -7442,8 +7556,8 @@
type PrivateNote @key(fields: "id") @shareable {
id: ID!
note: Note @provides(fields: "name author { id }")
}
type Query {
}
type Query {
note: Note @shareable
privateNote: PrivateNote @shareable
}
Expand All @@ -7461,8 +7575,8 @@
id: ID!
name: String
author: User
}
type User @key(fields: "id") {
}
type User @key(fields: "id") {
id: ID!
name: String
}
Expand Down Expand Up @@ -7490,7 +7604,7 @@
type Note @key(fields: "id") @shareable {
id: ID!
tag: String
}
}
`),
},
]);
Expand All @@ -7510,7 +7624,7 @@
@join__field(external: true, graph: FOO)
@join__field(graph: BAR)
tag: String @join__field(graph: BAZ)
}
}
`);
});

Expand Down
Loading