Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1119,33 +1119,31 @@ Amplify GraphQL schemas support the `extend` keyword, which allows you to extend

2. In one of the files (e.g., `schema1.graphql`), declare your type normally:

```graphql
```graphql title="schema1.graphql"
type Query {
# initial custom queries
myQuery: String @function(name: "myQueryFunction-${env}")
}
```

3. In other schema files (e.g., `schema2.graphql`), use the `extend` keyword to add to the type:

```graphql
```graphql title="schema2.graphql"
extend type Query {
# additional custom queries
myQuery2: String @function(name: "myQuery2Function-${env}")
}
```
<Callout info>
The order in which the Query types are extended does not affect the compilation of separate schema files.
</Callout>

<Callout info>
Declaring custom Query, Mutation, and/or Subscription with the same field names in another schema file will result in schema validation errors similar to the following:
The order in which the Query types are extended does not affect the compilation of separate schema files. However, declaring custom Query, Mutation, and/or Subscription extensions with the same field names in another schema file will result in schema validation errors similar to the following:

`🛑 Object type extension 'Query' cannot redeclare field getBlogById`
</Callout>

<Callout info>
Amplify directives are currently not supported on the extended type definitions. You can use the extend keyword to organize custom queries, mutations, and subscriptions that use [custom resolvers](https://docs.amplify.aws/gen1/react/build-a-backend/graphqlapi/best-practice/batch-put-custom-resolver/).
4. Add functionality to the fields of the extended type using Amplify directives. Amplify supports the `@auth`, `@function`, and `@http` directives on fields of `Query`, `Mutation`, and `Subscription` type extensions. Alternately, you can use the `extend` keyword to organize custom queries, mutations, and subscriptions that use [custom resolvers](https://docs.amplify.aws/gen1/react/build-a-backend/graphqlapi/best-practice/batch-put-custom-resolver/) rather than Amplify directives.

For the latest updates and potential future enhancements, please track the ongoing discussion in [GitHub Issue #3036](https://github.com/aws-amplify/amplify-category-api/issues/3036).
<Callout info>
Amplify directives are not supported on extended type definitions themselves (e.g., `extend type Todo @auth...`), or on fields of types other than `Query`, `Mutation`, and `Subscription`.
Copy link
Contributor

@josefaidt josefaidt Jan 30, 2025

Choose a reason for hiding this comment

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

the latter part of the callout reads a bit odd to me but it may just be me 😅

or on fields of types other than Query, Mutation, and Subscription

is this referring to fields in non-model types?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both model and non-model types are not supported. I agree the syntax is a bit convoluted -- can you suggest clearer wording?

Copy link
Contributor

Choose a reason for hiding this comment

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

is it accurate to say "or on fields of extended types other than..."?

Copy link
Member Author

@palpatim palpatim Jan 31, 2025

Choose a reason for hiding this comment

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

Yes, it is more accurate. I'm not sure it's any clearer, but would this work?

Amplify directives are not supported on extended type definitions themselves (e.g., extend type Todo @auth...), or on fields of extended types other than Query, Mutation, and Subscription.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes that works! When I read it initially I thought of model types despite the preceding context

</Callout>

## How it works
Expand Down
Loading