Skip to content
Open
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
36 changes: 36 additions & 0 deletions __tests__/composition.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2235,6 +2235,42 @@ testImplementations((api) => {
expect(result.publicSdl).not.toMatch(/lowercase/);
});

test("requires on field with arguments without providing said arguments should fail", () => {
let result = composeServices([
{
name: "a",
typeDefs: parse(/* GraphQL */ `
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key"]
)
type Query {
product(id:ID!): Product
}
type Product @key(fields: "id"){
id: ID!
description(filter: String!): String!
}
`),
},
{
name: "b",
typeDefs: parse(/* GraphQL */ `
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3"
import: ["@key", "@external", "@requires"]
)
type Product @key(fields: "id"){
id: ID!
description (filter: String!): String! @external
calculatedField: String! @requires(fields: "description")
}
`),
}
]);
assertCompositionFailure(result);
});
Comment on lines +2238 to +2272
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The indentation in this test case is inconsistent with the rest of the file. Aligning it with the surrounding tests will improve code readability and maintainability. I've also changed let to const as result is not reassigned, which is a good practice.

    test("requires on field with arguments without providing said arguments should fail", () => {
      const result = composeServices([
        {
          name: "a",
          typeDefs: parse(/* GraphQL */ `
            extend schema
              @link(url: "https://specs.apollo.dev/federation/v2.3"
                import: ["@key"]
              )
            type Query {
              product(id:ID!): Product
            }
            type Product @key(fields: "id"){
              id: ID!
              description(filter: String!): String!
            }
          `),
        },
        {
          name: "b",
          typeDefs: parse(/* GraphQL */ `
            extend schema
              @link(url: "https://specs.apollo.dev/federation/v2.3"
                import: ["@key", "@external", "@requires"]
              )
            type Product @key(fields: "id"){
              id: ID!
              description (filter: String!): String! @external
              calculatedField: String! @requires(fields: "description")
            }
          `),
        }
      ]);
      assertCompositionFailure(result);
    });


test("preserve directive from one subgraph if defined differently across subgraphs but one included in @composeDirective", () => {
const result = composeServices([
{
Expand Down