ardatan/graphql-import

Splitting scheme for Query / Mutations over multiple files ?

Closed this issue · 4 comments

Hi,

I have managed to split out my Types to seperate files and seems to be working. I was wondering if its possible to split out the Query / Mutations to separate files and have these consolidated into one

type Query

for example, I have 2 x queries into 2 different files.

type Query {
  feed: [Post!]!
  drafts: [Post!]!
}

type Query {
  user: [User!]!
}

This would create a scheme of the type Query like so

type Query {
  feed: [Post!]!
  drafts: [Post!]!
  user: [User!]!
}

I noticed from the docs that it is possible to split out the Mutations and Queries to separate files but wasn't sure if we could further split these down into multiple files per Query / Mutation.

Thanks in advance

Yes, that is possible. If you import Query from different files, the final scheme will be extended like in your example;

# import Query.* from "posts.graphql"
# import Query.* from "users.graphql"

Or you could do it like this;

# import Query.feed, Query.drafts from "posts.graphql"
# import Query.user from "users.graphql"

Great. Thank you.

I'll keep this open until it's better documented here: https://oss.prisma.io/graphql-import

It's better documented now on the page above 👍.