Replies: 9 comments 22 replies
-
Not sure what you mean, truck id is right there under trucks from plan schema, you can stitch from that. I may be misunderstanding the problem with your specific use case. In general with schema stitching now the first question is whether you want to use extension on the gateway or type merging. Extension on the gateway is more tried and true but type merging may be closer to what you want... |
Beta Was this translation helpful? Give feedback.
-
Oh, I see, you need to place the argument on a nested field, you can stitch to the inner field and then use WrapQuery or newer TransformQuery to wrap, TransformQuery I think may better support fragments (non inline) |
Beta Was this translation helpful? Give feedback.
-
Actually, I think WrapQuery and TransformQuery wrap the selectionSet and you want to wrap the root fields. You may need to create your own transform... |
Beta Was this translation helpful? Give feedback.
-
How did this go for you? I realize I never addressed how type merging would help. Type merging merges together types with the same name, so it would work only if the fbrTruck field and the trucks list field could be renamed to refer to the same underlying named type, perhaps Truck. In that case, the gateway will automatically query the other subschema for remaining fields. By default, you get all the root fields from both subschemas automatically merged. In order to make the magic happen, each subschema has to provide a way to get at that type. If it is simple, you can just specify the root field name and arguments -- if it is complex, you can write your own merged resolver. See: https://www.graphql-tools.com/docs/schema-stitching/#merging-types Your merged type resolver for the FDP schema might be something like this:
You don't actually indicate above how to get a truck directly from the PLAN subschema -- so the merging would work from a FDP root field. I believe the above would work even though the key fields seem to differ by name between the two schema (id vs uuid) because there are only two two subschemas, so you would always know which field within the original result you would need, but your other options are to rename the fields using transforms prior to merging to get a common key, or to use some logic to extract the key from the originalResult (something like originalResult.id ?? originalResult.uuid). I hope that's helpful! |
Beta Was this translation helpful? Give feedback.
-
https://github.com/ztolley/stitching_gateway/blob/master/src/graphql/index.js I'm so close it hurts. The schema produced it exactly what I want and I can get the truck.id BUT if I try to get any of the fields that come from fdpschema then it comes back with null. If I add some console commands to the fdpschema resolvers they aren't even called. I Can start to see what you are trying to do, I'm just at a loss as to what I'm doing wrong |
Beta Was this translation helpful? Give feedback.
-
Instead of: async function getSchema() {
return stitchSchemas({
subschemas: [
{ schema: fdpSchema },
{
schema: planSchema,
merge: {
FBRTruck: (originalResult, context, info, schema, selectionSet) =>
delegateToSchema({ Try: async function getSchema() {
return stitchSchemas({
subschemas: [
{ schema: fdpSchema },
{
schema: planSchema,
merge: {
FBRTruck: {
selectionSet: `{ id }`,
resolve: (originalResult, context, info, schema, selectionSet) =>
delegateToSchema({
} you may need And a reminder that the key you are referencing in selectionSet has to be in the original result, usually this should have the same name in both schemas, but in your example you have You may be able to get away with it because you are using a one-way merge, and I think based on the direction the selection set hint should be This hint is for what you need to be available under originalResult, i.e |
Beta Was this translation helpful? Give feedback.
-
Probably to avoid confusion. But whatever fields you have control over, now you have to consider why not just putting those types and fields in gateway itself with extend as necessary... Generally, delegation should be used only when necessary... |
Beta Was this translation helpful? Give feedback.
-
Ok, type merging is tricky here because:
Could you explain more what's going on with third point above? Why is that a list? You may need to flesh out more about the schema for those not so familiar with your use case. :) Apologies if this has been explained already. |
Beta Was this translation helpful? Give feedback.
-
Just tried setting up type-merging for all my tricky cases today including
a cross-service interface and a model in one app returning paginated
results from another app... and it all kinda “just works”. It’s really
remarkable how well this works Yaacov (kudos!!), and it’s both simpler in
service design than federation and feels more extensible. Plus I can start
incrementally rolling it out in my existing API without a system-wide
migration and cutover. I’ve still got to demo it all to my team, but there
is a very strong chance that we’ll be tabling our intentions of migrating
to federation later this year in light of these new capabilities. Awesome
work!
…On Mon, Jul 27, 2020 at 4:38 PM Yaacov Rydzinski ***@***.***> wrote:
Have to try it and find out though!
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1608 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAFRROG2AXZWKJXUWVZDKZ3R5XQTNANCNFSM4NXR7YDA>
.
|
Beta Was this translation helpful? Give feedback.
-
First of all, first time poster, long time user :) I appreciate the unique toolset that graphql-tools provides and I'm definitely thankful that it understands that schema stitching is still important a and we can't all just adopt federation.
I'm building a GraphQL API gateway to join 2 remote API's. The first backend (FDP) manages a list of trucks and stores information about them including how they use burn fuel. The 2nd backend (PLAN) is used for storing planning data and part of this involves defining which trucks take part in a plan. The two API's are maintained by remote teams and cannot be changed.
The aim is to create a gateway to act as a single GraphQL endpoint and stitch the related data together to give a single seamless API. As part of this the gateway will need to use a truck id from the plan and join that with the truck in the other datasource
The FDP API uses base types and then extends them for different types of data requested. A typical request to get a trucks name and fuel information would look like this:
To get information about a plan you would use:
So one proposed way to get all the data back in a singe query would be to use either:
Or, though may cause issues as schemas grows
I've setup a server at https://stitching-gateway.herokuapp.com/ that runs a copy of the code.
So the question?
All the documentation and examples for
delegateToSchema
describe its use in simple scenarios in which you specify a field in the Query object and a single field in the response. In this case though fetching the data does not follow that, it needs a more specific query and parameters passed down into that, plus the data requried is a few layers deep.delegateToSchema
?Beta Was this translation helpful? Give feedback.
All reactions