-
Notifications
You must be signed in to change notification settings - Fork 349
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
Transform-Replace-Field: Leads to null response (clash of user expectation). #3533
Comments
Hi @D1no, I have been debugging the issue and finding out the root cause. What's happening here is that json-schema handler receives an object like Finally, the resolver response is intercepted by the Replace field Transform, but this, instead, knows that the field that you wanted to replace was an object and so it expects to hoist a property from that object. So we end up with a handler that doesn't know anything about schema transformation and has logic to match resolver into an Array as the schema expects, and then a Transform which is is aware that schema before the transformation was of type object and so it expects to hoist a property from that object in order to adapt to the transformed schema. I hope I managed to make myself clear. Having said that, I do have a recommendation for you and this is to create a custom resolver composer that can hoist the value that comes back from the json-schema handler. All you need to do is to change your transform to this: transforms:
- replace-field:
replacements:
- from:
type: Query
field: sleep
to:
type: Sleep_History
field: sleep
# scope: hoistValue # no longer needed
composer: ./customComposers.js#sleep And then create a module.exports = {
sleep: next => async (root, args, context, info) => {
const sleep = await next(root, args, context, info);
return sleep[0].sleep;
},
}; The usage of Replace field Transform with custom composers is documented here, if you want to know more. Please let me know how this goes. |
Thank you very much @santino. Many rest APIs return the top level query and I already thought about writing some js to clean that up before hand, but wanted to stay in the 🐛 Anyway, regarding this issue here: The overall expectation-result feels like a bug to me
With the Thank you again @santino |
Thanks for your comment. I am a fond user of Run anywhere means that you can get the executable GraphQL schema running the way you wish, from the built-in tools that graphql-mesh provides, such as dev server and GraphiQL browser IDE, to your own custom server that you can build with Fastify, Restify, Express etc., to even serverless solutions. I believe A few additional comments.
If you need custom use cases, you do need custom-built code.
This is not quite true.
Replace Field transform is powerful and allows you to do a lot, the actual schema alteration is not naive and works as expected.
This makes it clear that
I agree that users cannot know the inners of graphql-mesh, but they're not required to! I just wanted to clarify a few things, but having said that, I believe we can do something to help on use cases like yours and I am discussing this with the team. I just do feel a bit sad when people decide to walk away because they have a scenario that still allows them to do things but in a slightly less ideal manner. |
First of all: Without Contributors like you, the whole open source ecosystem would be dead. You and all the other maintainers are the life blood that keeps projects like this alive. And that is important! From my personal OSS experience, I know how much ownership one takes to make things work — so please, I want to let you know that I feel with you. From my try with
So if I, as a User, need to do that, its much easier to just avoid learning (and be cautious of) the graphql-mesh dependency and do:
So the bug here is an issue in expectation: That graphql-mesh is smart enough to make sure it continues working, or warns about it, when you use its configuration capabilities. And that's maybe the reason why people walk away from it. The first impression for me was "things will just work as long as you stay within the configs". And that is a software architecture / design problem. Not contributor mistake. The "data-to-schema guarantee" functionality is simply not there / not made aware of. Which probably bit @rosswaycaster as well. Anyway, much love from Berlin |
Hi, I belief this is a bug.
I am connecting to a json rest API and I want to do this:
Problem: Schema is correctly changed, but output is null now
So by follwing the example in the Documentation, my
.meshrc.yaml
looks like this:REST API Return Sample
JSON Schema
Result
Output in the Console (DEBUG=1)
After transform, schema is as expected but the return is
null
Reproduction
As Codesandbox:
https://codesandbox.io/s/reproduction-graphql-mesh-json-api-transform-e0t4b?file=/.meshrc.yaml
The Reproduction Repository:
https://github.com/D1no/reproduction-graphql-mesh-json-api-transform
npm install
npm start
Schema: Before Transform
Schema: After Transform
Originally posted by @D1no in #3526 (comment)
The text was updated successfully, but these errors were encountered: