-
Notifications
You must be signed in to change notification settings - Fork 59
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
Using Bindings with Fragments for a Stitched Schema #70
Comments
Thanks a lot for your detailed description, @LawJolla. I am curious to hear the perspective of @kbrandwijk, @schickling and @freiksenet on this topic 🙂 |
I'm currently working on a very similar user case. I would like to know how to control which fields get requested when the function is used without info and some doc about |
Thanks a lot describing your use case @LawJolla (and apologies for the delayed response). We'll be looking into this over the following days. Can you please provide a minimal repo to reproduce your scenario? |
Thanks @schickling ! Here's the minimal repo. (I kept my development / shared endpoints in the code to make it faster on everyone) https://github.com/LawJolla/graphql-stitched-bindings-example |
Thanks a lot @LawJolla. @timsuchanek will look into this later this week! :) |
Thanks for the example repo @LawJolla ! One question: Here you're providing a separate schema definition for the stitching. Is there a particular reason to not put this into the We're now working on a utility function that will help with your use case addFragmentToInfo(info: GraphQLResolverInfo, fragment: string): GraphQLResolverInfo That solves your issue like this: addFragmentToInfo(idsAndInfo[0].info, 'fragment EnsurePostId on Image { postId }'), |
Thanks @timsuchanek , that would be perfect! I've tried putting the But no, there's no particular reason it's there other than I couldn't get it to work in the schema and Graphql-tools shows that pattern in their old examples. |
Re @LawJolla |
Awesome, thanks @schickling and @timsuchanek! I should be able to give it a spin today. |
Thanks for your help and I'm sorry for the long delay. I ran into errors and then had other business crap come up. I finally got back to it and it works great. The only thing that's confusing to me is I wanted to use it as..
But once I changed it to
It worked perfectly. Thanks for the help!! |
My questions are how to use fragments with bindings and how to use Dataloader with bindings.
To preface, I may be completely lost in my own head on this problem. So let me give the 100,000ft view and hopefully there's an answer.
I have two servers, one for vehicles and one for files. The vehicles server needs to stitch in the file server. The vehicle server wants to query:
heroImages
comes from the file server. Here's how I've implemented this so far.I used
get-schema
to save a copy of the file server to the vehicle server. I imported the needed types throughschema.graphql
.My app schema:
Then I build the binding for the file server
All good so far. But here's where things go sideways. Obviously
heroImages
is an N+1 call. So I made a Dataloader...And the resolver...
The first few problems rear their heads.
How to get
info
into the binding query. DataLoader's API is pretty strict. I've made it work by turning it into an object, but whoa hack...heroImagesLoader.load({ id: stockNo, info})
and then mapping the ids and passingids[0].info
for theinfo
binding parameter.How to get a field into the binding if it's not queried. In my set up, the vehicle server stores a
stockNo
for each vehicle. The file server groups files by a groupId. For vehicles, the stockNo is the groupId. Therefore, I cannot map the results back without knowing the groupId field. I'm sure there's a hack I could do toinfo
, but isn't there a better way?I tried messing with the binding's
fragmentReplacement
to no avail. e.g.to no avail.
Any help is a huge help! Thanks everyone as always for your time and effort!
The text was updated successfully, but these errors were encountered: