-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Support resolve on Input types #747
Comments
From what context would this There should be nothing stopping you from adding these functions to your schema, but I'm not understanding what code should be calling them. |
Hmm, in my example I was envisioning a world without input objects it seems :) pretend that the above types are InputObjects with The idea is that Graphql knows the schema much better than the dev and if you are using complex inputs it gets easy to forget to reverse the client mapping. Plus, if you manually call the unresolvers, you also have to do it depth-first, which gets hairy. |
The leaf nodes on input types coerce input into the correct shape - does that help? Or you want to have the ability to have, for example, an input type which is an array of values, but provide it to server code as a comma-separated string? |
That latter example, exactly.
…On Tue, Apr 25, 2017, 6:52 AM Lee Byron ***@***.***> wrote:
The leaf nodes on input types coerce input into the correct shape - does
that help? Or you want to have the ability to have, for example, an input
type which is an array of values, but provide it to server code as a
comma-separated string?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#747 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AADWlhiEgexd_7oyNz8K9Cw_k7Ydu142ks5rzXvzgaJpZM4MW0Uq>
.
|
Another example is where your database expects a normalized structure but the graphql mutation interface is the joined structure. Without a per-type Basically, |
I get the use case, conceptually, but it's still not quite clear to me when/how these |
I would expect these So suppose an inbound mutation has a |
How about just supporting const Foo = new GraphQLObjectType({
name: 'Foo',
fields: {
items: {
type: new GraphQLList(GraphQLString),
resolve: ({items}) => items.split(','),
},
},
})
const FooInput = new GraphQLInputObjectType({
name: 'FooInput',
fields: {
items: {
type: new GraphQLList(GraphQLString),
resolve: (_, items) => items.join(','),
},
},
}) The resolvers would get called right after the value is parsed, so depth-first. Signature could be
|
@wmertens I think this issue partly overlaps with #361 (comment) But for argument transformation, I think it should be done inside resolvers. The resolver should receive arguments that match field definition especially since it's documented in the specification: http://facebook.github.io/graphql/June2018/#sec-Value-Resolution |
@IvanGoncharov there is no overlap because that issue is about output types and there is even a workaround possible by decorating the schema. However, input types have no transformation possibilities besides creating a scalar type per resolver, which would even cause the schema to change. I also disagree that this is precluded by the spec, since the spec is purely about the schema and this is implementation-specific. I really think that adding this simple feature will lead to less mutation resolver code with better reuse and thus higher quality. |
@wmertens If we allow changing types of arguments than resolvers will stop being type-safe. For example, you lose the ability to generate typings for your arguments, like this: https://github.com/nknapp/graphql-typewriter/blob/master/test/schemas/arguments.ts#L8 It also a problem for any GraphQL middleware that will try to wrap Scalars are the only place where |
Types are nice, but now you're using them as an argument against something that would improve code quality? |
Actually I'm not sure that we're on the same page. I am only requesting a nicer way to map graphql inputs to their server-side equivalents, just like output resolvers are a nice way to map server-side data to graphql. |
Fwiw, I would also very much like to see this. I think it also comes up when you're working with an existing database that has snake_case columns and you want to provide a camelCase graphql interface. In the output types it's trivial to throw in resolvers like
But for input types you're kinda hosed, you just have to find somewhere you can slip some parsing / formatting code in without causing too much trouble. |
This is a pretty big proposal so I think it should first be implemented outside of Currently, we focusing on adding functionality to allow implementing such feature outside of |
@IvanGoncharov but these inputtype field resolvers have to run during the parsing of the input data given to graphql-js, otherwise they can't do depth-first. Mutation resolvers run after that so then it is too late. Would it maybe be possible to add a callback function that runs after each input parsing, for prototyping this? |
@wmertens Middleware 100% would support pre resolver callback in which you can replace args and also you will have access to argument types. So you can run |
– @IvanGoncharov, #747 (comment)
– @stubailo, ardatan/graphql-tools#652 (comment) This issue feels a bit like a hot potato at the moment. |
Update: see #747 (comment)
Creating an API for reading data is easy now, thanks in part to per-field resolvers that allow you to map from server-side domains to the client domain in a piecewise manner. However, there is no corresponding function to go from client to server domain.
How about adding
unresolve(root, args, context, info)
to the field definition?I think it would make sense if it was allowed to mutate root, and it would return the server-domain value of its field. So this would enable:
Right now, to do this, you need to manually traverse the input arguments to apply the transformations where needed.
The text was updated successfully, but these errors were encountered: