Skip to content
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

Field Argument Type Rewriter Transform #3960

Open
AndresPerezTesela opened this issue May 21, 2022 · 3 comments
Open

Field Argument Type Rewriter Transform #3960

AndresPerezTesela opened this issue May 21, 2022 · 3 comments

Comments

@AndresPerezTesela
Copy link

It would be very helpful to additional transforms for field arguments. Currently only argument renaming is supported, but not argument retyping.

An alternative solution is what this repo offers https://github.com/graphql-query-rewriter/core. But it is much more limited to graphql-mesh since it only offers field argument rewriting. And it wouldn't be very clean to use it in conjunction with graphql-mesh.

A proposed solution would be to add an experimental field argument type transform that leverages this alternative pkg, or maybe extend the rename tool to also be able to change argument types.

@mattduggan
Copy link

My use case: adding a required argument for all operations to context. I'd like to be able to state that a required argument is optional so that the value doesn't have to be passed in as a variable to the hooks, but is pulled from context in the resolver.

@ardatan
Copy link
Owner

ardatan commented Aug 29, 2023

Instead of a transform, you can add a new field and use @resolveTo directive to the actual field then set the argument value from the context.
Let's say this is the existing schema

type Query {
 foo(id: ID!): Foo
}

Then you add the following;

extend type Query {
 myFoo: Foo @resolveTo(
      sourceName: "FOO_SOURCE"                                   # Which source does the target field belong to?
      sourceTypeName: "Query",                                # Which root type does the target field belong to?
      sourceFieldName: "foo", # What is the source field name?
      sourceArgs: {                                           # What args the source field does need?
        id: "{context.myFooId}"
      }
    )
}

@mattduggan
Copy link

@ardatan Thank you for the response and the example.

I'm concerned that this approach would be rather cumbersome to migrate to and maintain. Ideally, I want to be able to configure, in a declarative way, "for every argument fooId, resolve to context fooId".

@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants