Replies: 3 comments 1 reply
-
This is not possible currently. You have to implement your own additional resolvers that fetch from both sources. |
Beta Was this translation helpful? Give feedback.
-
Hello, is there any update about this situation? Is there any way to pull the same type from 2 different sources? |
Beta Was this translation helpful? Give feedback.
-
I've just gone through this with six identical sources (graphql handler) so can share my solution. I also thought this would be a common use case where there would be a simple pattern to follow but not so! The basic steps are:
Using three identical mock graphql server with two root nodes of "hello" and "greetings", encapsulate (don't be confused with the encapsulate transformer of graphql-mesh) them into a new root node of "switcher" with a variable of "client", the
You only need to handle the root nodes in the resolver, all nested nodes work fine. |
Beta Was this translation helpful? Give feedback.
-
I'm having a hard time understanding the best way to achieve what feels like a pretty straightforward goal. Perhaps my data source situation is unconventional?
I have 2 sources, both GraphQL endpoints.
Each schema defines the same
Project
entity:With 100% confidence we can say that each source has completely unique Projects by the
id
field - noProject
with the same ID will ever appear in both sources. Each source also has the same query interface for projects, i.e. the ability to order query by name.I want to provide a single query,
projects()
that supports the project filters shared by each source and returns an intelligently stitched (i.e. respects order args) result of Projects from each source.What I am unclear on:
• should this be supported out of the box if the types match?
• would renaming types on each source and then using the rename transformation help? (i.e. the AuthorWithBooks => Author rename example)
• is this appropriate for the type merging transformation?
• is my reliance on additional resolvers is the best way to accomplish this?
Additional Resolvers
I wrote my own resolver, it's so simple it feels like it should not be needed? But it breaks any notion of ordering from the outside query which would be not super fun to implement myself. Otherwise this works well.
Out of Box
Using the exact same entity definitions on each source and without any transforms, I seem to only get results from one of the sources.
Rename Transform
I also tried naming the source types differently and then using a rename transform to make them the same in the unified schema, but this had the same result as the previous attempt, where things where types were named the same in each source.
Type Merging
I also tried extending the rename with type merging, but not sure it's really a fit? The keyArg part would be a negation, where we find to query projects in SourceB where the ID is not in the list of projects from SourceA? Which shouldn't matter because SourceA IDs will never appear in SourceB?
Other approaches?
I don't have any more ideas here, hoping I'm just missing something.
Simply put, what's the mesh way for unifying query results across sources for a common entity, where entity instances only ever appear in one source?
Beta Was this translation helpful? Give feedback.
All reactions