Skip to content

feat(amplify-data): enhance discussion of split schema files #8228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Changes from all commits
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 extended types other than `Query`, `Mutation`, and `Subscription`.
</Callout>

## How it works
Expand Down
Loading