Navigation Menu

Skip to content
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

Merge remote GraphQL schema into a nested structure #961

Closed
billxinli opened this issue Sep 26, 2018 · 3 comments
Closed

Merge remote GraphQL schema into a nested structure #961

billxinli opened this issue Sep 26, 2018 · 3 comments
Labels
docs Focuses on documentation changes feature New addition or enhancement to existing solutions

Comments

@billxinli
Copy link

/label discussion

Assume I have n remote schemas, and I would like to merge the Query, Mutation and Subscription from different schemas into a single schema, except, each remote schema is placed under their own type.

Assume we have a remote schema called MenuX with:

type Item {
  id: Int!
  description: String
  cost: Int
}

type Query {
  items: [Item]
}

and a remote schema called MenuY with:

type Item {
  id: Int!
  name: String
  cost: Int
}

type Query {
  items: [Item]
}

I would like to merge the schema into a single schema but under their own types. A contrived example:

type MenuXItem {
  id: Int!
  description: String
  cost: Int
}

type MenuYItem {
  id: Int!
  name: String
  cost: Int
}

type MenuXQuery {
  items: [MenuXItem]
}

type MenuYQuery {
  items: [MenuYItem]
}

type Query {
  MenuX: MenuXItem
  MenuY: MenuYItem
}

As we can see that under the Query type it contains two new types which contain the query type from the remote schemas. Item from schema MenuX have been renamed by using the transformers from graphql-tools, similarly Item from schema MenuY has been transformed as well.

But is it possible to transform the structure as well?

With the actual remote schemas from Contentful, we are looking at hundreds of types from each schema, and ideally, I would like to not pollute the root types and the Introspection documentation in GraphiQL.

But I think the bigger discussion is what is the standard with merging schemas? Merge in a flat structure or nested structure?

@ghost ghost added discussion docs Focuses on documentation changes feature New addition or enhancement to existing solutions labels Sep 26, 2018
@Atomox
Copy link

Atomox commented Dec 11, 2018

For reference, you're not the first. See:

It seems others want to go the direction of prefixing the types, but I agree that the root namespace should not be polluted. I've been digging into a way to achieve this locally without a major hack. It seems to me that if we're already mounting remote schemas into our local schema, it should cost us little effort in order to add structure. After all, were we writing this ourselves, we could easily achieve this. There is something to be said for semantic namespacing, which is not only cleaner, but self-documenting.

I would love to see more movement on this.

@yaacovCR
Copy link
Collaborator

Solved with WrapType transform. Folded into #1306 .

@yaacovCR yaacovCR mentioned this issue Mar 30, 2020
22 tasks
@yaacovCR
Copy link
Collaborator

WrapType would not work for mutations or subscriptions. Best bet would be a spec update that supports namespaces, see graphql/graphql-spec#163

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Focuses on documentation changes feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

3 participants