#split schema files

10 messages · Page 1 of 1 (latest)

last knot
#

Hello, how are people??
Has anyone had experience splitting the schema.graphql file into different files for better scalability when implementing in a Next.js application with Amplify? I'm encountering an error stating 'There can be only one type named "Query"'. Are there any additional documentation or code examples available to effectively achieve this

analog sapphire
#

Hi @last knot can you share what version of the Amplify CLI you’re using and the schemas you’re trying to separate?

#

This is to try and get some reproduction steps so I can trigger the same error on my end

last knot
#

Hi amplify --version
12.8.2

I have this architecture for default,

#

however i need put this format

#

when i run amplify api gql-compile

analog sapphire
#

Oh, you have two instances of type Query across your schema files. These schemas are concatenated by the Amplify CLI so it's parsing it as appearing twice rather than consolidating/merging the nested fields into one Query type.

You can either simply declare your custom queries in one Query.graphql file or, in your case, you can use the extend keyword like so:

# schema1.graphql
type Query {
  #custom query
}

# schema2.graphql
extend type Query {
  #custom query
}

Where you begin using extend doesn't seem to matter, but give that a try and let me know if you're able to compile your schema files 🙂

last knot