-
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
Wrap mode for replace-field transform #3498
Comments
We'd love to accept a PR for this feature :) |
@ardatan I think we should come back to the plan of splitting Replace Field transform with two different transforms. The first step is to look at this PR which I had ready in Mid November (hence might need some updates, but it's there): The second step is to look into the Hoist Field transform, which has a PR by @ntziolis in #2862 I believe that Hoist Field transform might be enough to cover the use-case for this issue. |
Actually, Hoist Field transform might not be enough for this use-case. @avallete have you tried extending the schema to introduce a new field? You can take a look at this guide for some references. # meshrc.yaml
transforms:
- filterSchema:
filters:
- File.!last_version
additionalTypeDefs: |
extend type File {
latest_version: file_version!
}
additionalResolvers:
- ./src/mesh/additional-resolvers.js // src/mesh/additional-resolvers.js
const resolvers = {
File: {
latest_version: (root, args, context, info) => {
return root.last_version[0];
}
}
}
module.exports = { resolvers }; It might sound like more work, but It's actually similar since even with the Replace field Transform you'd have to write the additional type and additional resolver. I think this might help, but didn't try, so give it a go and let us know. |
Your solution works perfectly ! Thanks for your minimal example ! I did try something similar went I stumbled upon the guide that you linked but I wasn't able to make it work. It may be a good thing to link with a similar example that you provided to the "replace-field" docs section. To explain that this is a good alternative for graphql api's. |
Glad it worked. Replace Field transform is very powerful, but I believe that with can cover most scenarios with better distributed Transforms, like Transforms Schema and Hoist Field. Once we move forward with those Transforms, I will look into updating the documentation to hopefully make things more explicit. |
Is it possible to use this technique to override a field with a type that doesn't exist in the original schema? For example...original schema: type Artwork {
id: ID!
title: String!
} Filter: transforms:
- filterSchema:
filters:
- Artwork.!title
extend type Artwork {
title: TextDisplayField!
}
type TextDisplayField {
label: String
value: String!
} This works fine if I override
|
What you are describing seems mostly a schema extension rather than a field replacement. The guide for schema extensions is here, take a look at it and have a play. |
Thanks...how would that be different from what I'm already doing, where I have |
Should I open a new issue about this? I'm just trying to use |
Ok this issue seems too heated. So please create a new issue with a clear and minimal reproduction. |
Ok I opened a new issue here: |
Is your feature request related to a problem? Please describe.
I am currently using graphql-mesh as a proxy in front of an hasura. Since the
schema.graphql
is automatically generated by hasura API and sometimes mismatch what I would like to consume, it would be convenient to use the "replace-field" to "correct" the types of hasura.Example:
Then into the resolver:
Describe the solution you'd like
As for now, the "replace-field" transform, only work properly with the "bare" mode, which is incompatible with an "already graphql" API. It would be perfect if it work the same with "wrap" mode, or if we had an alternative to achieve what I want to do.
Describe alternatives you've considered
I've tried to check on additional-resolvers but they don't seem fit to my need.
Additional context
From my tests, for now, the "replace-field" transform works well with "graphql" API as long as the "schema types rewriting" goes (I've been able to replace the type of
last_version
with the one I wanted). However, it does crash at runtime when trying to get the value.The text was updated successfully, but these errors were encountered: