Skip to content

fix(schema): allow @canonical, @hidden, @renamed on FIELD_DEFINITION#684

Open
PatrykMilewski wants to merge 1 commit intosid88in:masterfrom
PatrykMilewski:fix/widen-merge-directive-locations
Open

fix(schema): allow @canonical, @hidden, @renamed on FIELD_DEFINITION#684
PatrykMilewski wants to merge 1 commit intosid88in:masterfrom
PatrykMilewski:fix/widen-merge-directive-locations

Conversation

@PatrykMilewski
Copy link
Copy Markdown

@PatrykMilewski PatrykMilewski commented Apr 30, 2026

Summary

AWS_TYPES in src/resources/Schema.ts declared @canonical, @hidden, and @renamed only on the OBJECT location. AWS's Merged API best-practices guide explicitly applies these directives to fields too:

  • rating: Int @canonical@canonical on FIELD_DEFINITION
  • authorId: ID! @hidden@hidden on FIELD_DEFINITION
  • getMessage(id: ID!): Message @renamed(to: "getChatMessage")@renamed on FIELD_DEFINITION

The narrow stub causes local SDL validation (validateSDL) to reject schemas that follow AWS's documented usage:

Invalid GraphQL schema:
     Directive "@canonical" may not be used on FIELD_DEFINITION.
     Directive "@hidden" may not be used on FIELD_DEFINITION.

Changes

- directive @canonical on OBJECT
- directive @hidden on OBJECT
- directive @renamed on OBJECT
+ directive @canonical on OBJECT | FIELD_DEFINITION
+ directive @hidden on OBJECT | FIELD_DEFINITION
+ directive @renamed on OBJECT | FIELD_DEFINITION

Plus a regression test (schema.test.tsshould accept merged-API directives on OBJECT and FIELD_DEFINITION) with a fixture schema that uses each directive in both locations.

Known follow-up not included here: the @renamed(to: String!) argument

AWS's actual @renamed directive takes a required to: String! argument, e.g. @renamed(to: "newName"). The fully AWS-spec-aligned declaration would be:

directive @renamed(to: String!) on OBJECT | FIELD_DEFINITION

This PR intentionally does not add the argument, because doing so would be a breaking change: any existing user writing @renamed without an argument (which the current directive @renamed on OBJECT stub allows) would suddenly fail SDL validation with Argument "to" of required type "String!" was not provided. That fix should be addressed separately — likely behind a major-version bump or with a dedicated migration note. Mentioning it here so it isn't lost.

Tests

npx jest src/__tests__/schema.test.ts → 6 passed (including the new test).
Full suite still passes for actual test files.

Refs


This pull request is generated by a Claude Code Agent.

The bundled directive declarations restricted @canonical, @hidden, and
@renamed to OBJECT only, causing local SDL validation to reject schemas
that apply them to fields. AWS's Merged API spec and best-practices
documentation explicitly support FIELD_DEFINITION usage, e.g.:

  rating: Int @canonical
  authorId: ID! @hidden
  getMessage(id: ID!): Message @renamed

Widen the location set to OBJECT | FIELD_DEFINITION.

Note: AWS's @renamed directive also takes a `to: String!` argument
(e.g. `@renamed(to: "newName")`). Adding it to this stub would break
existing users who write `@renamed` without an argument, so it is left
out of this change. See PR description for details.

Refs: https://aws.amazon.com/blogs/mobile/aws-appsync-merged-apis-best-practices-part-2-schema-composition/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant