Skip to content
Closed
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions packages/utils/tests/print-schema-with-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,4 +402,22 @@ describe('printSchemaWithDirectives', () => {
expect(output).toContain('input OneOfInput @oneOf');
}
});
it('should allow duplicate directives', () => {
const typeDefs = `
extend schema
@link(
url: "https://specs.apollo.dev/federation/v2.5"
import: [
"@tag"
]
)

scalar DateTimeISO @tag(name: "nameA") @tag(name: "nameB")
`;
const schema = buildSchema(typeDefs);
const printedTransformedSchema = printSchemaWithDirectives(schema);
expect(printedTransformedSchema).toContain('nameA');
expect(printedTransformedSchema).toContain('nameB');
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Strengthen assertions to verify complete directive syntax.

The current assertions only check for the presence of "nameA" and "nameB" strings, which could produce false positives if these values appear elsewhere in the schema (e.g., in type names, field names, or other directive arguments).

Consider verifying the full directive syntax to ensure both @tag directives are correctly printed:

    const printedTransformedSchema = printSchemaWithDirectives(schema);
-   expect(printedTransformedSchema).toContain('nameA');
-   expect(printedTransformedSchema).toContain('nameB');
+   expect(printedTransformedSchema).toContain('@tag(name: "nameA")');
+   expect(printedTransformedSchema).toContain('@tag(name: "nameB")');
+   // Optionally verify both appear on the same scalar
+   expect(printedTransformedSchema).toMatch(
+     /scalar DateTimeISO[^\n]*@tag\(name: "nameA"\)[^\n]*@tag\(name: "nameB"\)/
+   );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
expect(printedTransformedSchema).toContain('nameA');
expect(printedTransformedSchema).toContain('nameB');
expect(printedTransformedSchema).toContain('@tag(name: "nameA")');
expect(printedTransformedSchema).toContain('@tag(name: "nameB")');
// Optionally verify both appear on the same scalar
expect(printedTransformedSchema).toMatch(
/scalar DateTimeISO[^\n]*@tag\(name: "nameA"\)[^\n]*@tag\(name: "nameB"\)/
);
🤖 Prompt for AI Agents
In packages/utils/tests/print-schema-with-directives.spec.ts around lines 419 to
420, the two assertions only check for the bare strings "nameA" and "nameB"
which can yield false positives; update them to assert the full directive syntax
(e.g., check for the exact printed directive tokens such as '@tag(name:
"nameA")' and '@tag(name: "nameB")' or use a regex that matches the directive
and argument structure) so the test verifies the directives themselves rather
than just the substring.


})
});
Loading