fix(schema): allow @canonical, @hidden, @renamed on FIELD_DEFINITION#684
Open
PatrykMilewski wants to merge 1 commit intosid88in:masterfrom
Open
fix(schema): allow @canonical, @hidden, @renamed on FIELD_DEFINITION#684PatrykMilewski wants to merge 1 commit intosid88in:masterfrom
PatrykMilewski wants to merge 1 commit intosid88in:masterfrom
Conversation
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/
a9d9581 to
e91f5fa
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AWS_TYPESinsrc/resources/Schema.tsdeclared@canonical,@hidden, and@renamedonly on theOBJECTlocation. AWS's Merged API best-practices guide explicitly applies these directives to fields too:rating: Int @canonical—@canonicalonFIELD_DEFINITIONauthorId: ID! @hidden—@hiddenonFIELD_DEFINITIONgetMessage(id: ID!): Message @renamed(to: "getChatMessage")—@renamedonFIELD_DEFINITIONThe narrow stub causes local SDL validation (
validateSDL) to reject schemas that follow AWS's documented usage:Changes
Plus a regression test (
schema.test.ts→should 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!)argumentAWS's actual
@renameddirective takes a requiredto: String!argument, e.g.@renamed(to: "newName"). The fully AWS-spec-aligned declaration would be:This PR intentionally does not add the argument, because doing so would be a breaking change: any existing user writing
@renamedwithout an argument (which the currentdirective @renamed on OBJECTstub allows) would suddenly fail SDL validation withArgument "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
sf-core.js): AppSync: @canonical, @hidden, @renamed directives rejected on FIELD_DEFINITION (only OBJECT supported) serverless/serverless#13533This pull request is generated by a Claude Code Agent.