Skip to content

fix(appsync): allow @canonical, @hidden, @renamed on FIELD_DEFINITION#13542

Merged
czubocha merged 1 commit into
mainfrom
sc-3948
May 5, 2026
Merged

fix(appsync): allow @canonical, @hidden, @renamed on FIELD_DEFINITION#13542
czubocha merged 1 commit into
mainfrom
sc-3948

Conversation

@czubocha
Copy link
Copy Markdown
Contributor

@czubocha czubocha commented May 4, 2026

Summary

The bundled AppSync schema validator declares the Merged API directives @canonical, @hidden, and @renamed only on the OBJECT location, causing valid schemas that apply them to fields to be rejected at packaging time:

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

AWS's Merged API devguide explicitly documents these directives as applying to "types/fields" and shows field-level usage in official examples, e.g.:

getMessage(id: ID!): Message @renamed(to: "getChatMessage")

This change extends each of the three directive declarations to OBJECT | FIELD_DEFINITION, matching AWS's documented surface.

Changes

  • packages/serverless/lib/plugins/aws/appsync/resources/Schema.js — broaden @canonical / @hidden / @renamed directive locations to OBJECT | FIELD_DEFINITION.
  • packages/serverless/test/unit/lib/plugins/aws/appsync/graphql-tools-merge-compat.test.js — keep inline AWS_TYPES copy in sync.
  • packages/serverless/test/unit/lib/plugins/aws/appsync/schema.test.js + new fixtures/schemas/merged-api/schema.graphql — regression test that runs the directives through Schema.generateSchema() (which calls validateSDL) on both OBJECT and FIELD_DEFINITION.

Out of scope

AWS's actual @renamed directive takes a required to: String! argument (@renamed(to: "newName")). Adding that argument to the local declaration would be a breaking change for any user currently relying on the lenient bare @renamed permitted by today's stub, so it is intentionally not part of this fix and should be addressed separately.

Test plan

  • Unit tests pass (schema.test.js, graphql-tools-merge-compat.test.js)
  • End-to-end: minimal AppSync service using @canonical and @hidden on FIELD_DEFINITION packages successfully against the source build
  • Existing tests and snapshots remain green

Closes #13533

Summary by CodeRabbit

  • New Features

    • AppSync schema directives now support application to both object types and individual field definitions, enabling more granular control over API schema configuration and metadata.
  • Tests

    • Added test fixtures and coverage to validate expanded directive compatibility across different schema elements.

Note

Low Risk
Low risk: expands local AppSync directive stubs used for SDL validation and adds regression tests/fixtures; no runtime behavior or data handling changes beyond schema validation acceptance.

Overview
AppSync schema validation now accepts Merged API directives @canonical, @hidden, and @renamed on both OBJECT and FIELD_DEFINITION, preventing packaging failures for schemas that annotate fields.

Adds a new merged-API schema fixture and a unit test to ensure Schema.generateSchema() validates successfully with these directives applied at field level, and updates the merge compatibility test’s AWS_TYPES stub to match.

Reviewed by Cursor Bugbot for commit fab8b24. Bugbot is set up for automated code reviews on this repo. Configure here.

The bundled AppSync schema validator declared these Merged API
directives only on the OBJECT location, rejecting valid schemas that
apply them to fields. AWS's Merged API devguide explicitly documents
these directives on "types/fields" and shows field-level usage in
official examples (e.g. `getMessage(id: ID!): Message @renamed(to: ...)`).

Closes #13533
@Mmarzex
Copy link
Copy Markdown
Contributor

Mmarzex commented May 4, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 4, 2026

📝 Walkthrough

Walkthrough

The PR expands three AppSync Merged API directives (@canonical, @hidden, @renamed) from OBJECT-only placement to both OBJECT and FIELD_DEFINITION locations in the bundled schema validator, aligning with AWS documentation and allowing these directives on fields as well as types.

Changes

AppSync Merged API Directive Expansion

Layer / File(s) Summary
Core Directive Definitions
packages/serverless/lib/plugins/aws/appsync/resources/Schema.js
Updated AWS_TYPES SDL: @canonical, @hidden, and @renamed directives changed from on OBJECT to on OBJECT | FIELD_DEFINITION.
Test Fixture Schema
packages/serverless/test/unit/lib/plugins/aws/appsync/fixtures/schemas/merged-api/schema.graphql
New fixture defines Query type with @canonical, @hidden, and @renamed directives applied to fields (user, internalAuthority, legacyMessage) and corresponding object types.
Merge Compatibility
packages/serverless/test/unit/lib/plugins/aws/appsync/graphql-tools-merge-compat.test.js
Updated embedded AWS_TYPES fixture to mirror core schema change: directives now allow OBJECT | FIELD_DEFINITION.
Validation Tests
packages/serverless/test/unit/lib/plugins/aws/appsync/schema.test.js
Added test case verifying Schema.generateSchema() accepts directives on both locations without error using the merged-api fixture.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Directives bloom on fields and types alike,
No more rejection of AWS's style,
@canonical hops to both OBJECT and FIELD,
Merged APIs now dance across the schema field,
Validation passes—hop, skip, and smile!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: broadening three AppSync directives to support field definitions, which is the primary fix in this PR.
Linked Issues check ✅ Passed The PR fully addresses issue #13533 by allowing @canonical, @hidden, and @renamed directives on both OBJECT and FIELD_DEFINITION locations, matching AWS documentation and resolving the reported validation error.
Out of Scope Changes check ✅ Passed All changes align with the stated objective; the PR intentionally excludes adding the required 'to' argument to @renamed as a breaking change to be addressed separately, as documented in the PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sc-3948

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@czubocha
Copy link
Copy Markdown
Contributor Author

czubocha commented May 4, 2026

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit fab8b24. Configure here.

@czubocha czubocha merged commit 3d3b0c8 into main May 5, 2026
15 of 16 checks passed
@czubocha czubocha deleted the sc-3948 branch May 5, 2026 14:31
@github-actions github-actions Bot locked and limited conversation to collaborators May 5, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AppSync: @canonical, @hidden, @renamed directives rejected on FIELD_DEFINITION (only OBJECT supported)

2 participants