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

Make it easy to prevent merging of root query fields #439

Closed
brunolemos opened this issue Oct 17, 2017 · 9 comments
Closed

Make it easy to prevent merging of root query fields #439

brunolemos opened this issue Oct 17, 2017 · 9 comments

Comments

@brunolemos
Copy link

brunolemos commented Oct 17, 2017

When merging multiples apis (e.g. GitHub and Yelp), instead of generating this schema:

{
    getRepositoryById(id: String!),
    # ...otherGitHubQueries,
    searchPlaceByName(place: String!)
    # ...otherYelpQueries,
    myCustomQuery,
}

I'd prefer to be able to generate this:

{
    github: {
        getRepositoryById(id: String!),
        # ...otherGitHubQueries,
        myCustomGitHubQuery,
    yelp: {
        searchPlaceByName(place: String!),
        # ...otherYelpQueries,
        myCustomYelpQuery,
    },
    myProjectNameHere: {
        # ...myCustomQueries,
    }
}

Is that possible or planned?
Thank you.

@freiksenet
Copy link
Contributor

We want to add namespacing utilities so that one can namespace stuff this way before merging. You can also filter the query after mergingSchemas, through eg https://github.com/graphcool/graphql-transform-schema.

@lifeiscontent
Copy link

@freiksenet any idea when this namespacing functionality will be finished? The project I'm working on really needs this kind of feature.

@flippidippi
Copy link

I think this is super important when using an in house schema and stitching to a schema that can change often, like GraphCMS. Instead of having to deal with multiple graphql endpoints or making sure the two schemas don't collide, we could easily do something like the following:

query {
  user {
    id
  }
  cms {
    pages {
      id
      title
    }
  }
}

where all of our often changing CMS schema is namespaced safely and won't interfere with our own schema.

@brunolemos
Copy link
Author

I believe this is now possible with the new graphql-tools 3.0!
Does anyone have an example?

https://dev-blog.apollodata.com/the-next-generation-of-schema-stitching-2716b3b259c0

@brunolemos brunolemos changed the title Schema Stitching: Allow wrapping schema on one specific field instead of merging root fields Schema Stitching: Allow wrapping schema on one specific field (namespace) instead of merging root fields May 12, 2018
@terion-name
Copy link

Such a requested (and obvious) feature and no receipt yet ((

@stubailo stubailo changed the title Schema Stitching: Allow wrapping schema on one specific field (namespace) instead of merging root fields Make it easy to prevent merging of root query fields Jul 14, 2018
@stubailo
Copy link
Contributor

This is a great idea! I think it's just a matter of implementing the right transform and making it easy to use/documented.

Anyone want to help with that?

@terion-name
Copy link

Currently I have an implementation that makes this by renaming types in remote schemas and constructing a new schema with service-specific fields, that have resolvers that delegate queries to corresponding remote schemas. I feel that my implementation is very rough and not very efficient, but the concept is something like this:

  1. Collect remote executable schemas
  2. Transform them be prefixing types (including root types) to prevent naming conflicts
  3. Based on all their data construct a new schema with root fields and "service" fields in them, each of which has a resolver, that simply delegates queries to corresponding remote schemas

@Atomox
Copy link

Atomox commented Dec 11, 2018

I honestly feel that renaming types (as documented in 3.0) doesn't go far enough to resolve this issue for larger datasets.

If you are using GraphQL as a proxy to host many remote APIs under a single server, then merging upwards of a dozen or more remote schemas will get messy, particularly when there are multiple root-level nodes on each schema. Adding a root stub where a remote schema can be attached is much cleaner and more scalable than simply prefixing types with a schema-specific value.

Has anyone been able to do this successfully?

@yaacovCR
Copy link
Collaborator

yaacovCR commented Mar 27, 2020

WrapType transform can be used on the root type to namespace. Also see the Gatsby transforms that achieve this.
Folded into v5 roadmap #1306, which merges improvements from graphql-tools-fork, including WrapType.

@yaacovCR yaacovCR mentioned this issue Mar 27, 2020
22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants