Skip to content

Commit a9d9581

Browse files
fix(schema): allow @canonical, @hidden, @renamed on FIELD_DEFINITION
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(to: "getChatMessage") Widen the location set to OBJECT | FIELD_DEFINITION and add the missing `to: String!` argument on @renamed so the validator accepts the form documented by AWS. Refs: https://aws.amazon.com/blogs/mobile/aws-appsync-merged-apis-best-practices-part-2-schema-composition/
1 parent 8f165c3 commit a9d9581

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
type Query {
2+
getUser(id: ID!): User! @canonical
3+
internalUser(id: ID!): User! @hidden
4+
legacyUser(id: ID!): User! @renamed(to: "modernUser")
5+
}
6+
7+
type User @canonical {
8+
id: ID!
9+
name: String! @canonical
10+
email: String! @hidden
11+
oldField: String @renamed(to: "newField")
12+
}
13+
14+
type Post @hidden {
15+
id: ID!
16+
}
17+
18+
type Comment @renamed(to: "Reply") {
19+
id: ID!
20+
}

src/__tests__/schema.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,18 @@ describe('schema', () => {
153153
`);
154154
});
155155

156+
it('should accept merged-API directives on OBJECT and FIELD_DEFINITION', () => {
157+
const api = new Api(
158+
given.appSyncConfig({
159+
schema: [
160+
'src/__tests__/fixtures/schemas/merge-directives/schema.graphql',
161+
],
162+
}),
163+
plugin,
164+
);
165+
expect(() => api.compileSchema()).not.toThrow();
166+
});
167+
156168
it('should return single files schemas as-is', () => {
157169
const api = new Api(given.appSyncConfig(), plugin);
158170
const schema = new Schema(api, [

src/resources/Schema.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ directive @aws_cognito_user_pools(
1818
cognito_groups: [String]
1919
) on FIELD_DEFINITION | OBJECT
2020
directive @aws_subscribe(mutations: [String]) on FIELD_DEFINITION
21-
directive @canonical on OBJECT
22-
directive @hidden on OBJECT
23-
directive @renamed on OBJECT
21+
directive @canonical on OBJECT | FIELD_DEFINITION
22+
directive @hidden on OBJECT | FIELD_DEFINITION
23+
directive @renamed(to: String!) on OBJECT | FIELD_DEFINITION
2424
scalar AWSDate
2525
scalar AWSTime
2626
scalar AWSDateTime

0 commit comments

Comments
 (0)