-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Labels
Description
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:
- re-packing/mapping fields:
const Foo = new GraphQLObjectType({
name: 'Foo',
fields: {
items: {
type: new GraphQLList(GraphQLString),
resolve: ({items}) => items.split(','),
unresolve: (_, items) => items.join(','),
},
},
})
- renaming fields:
const Foo = new GraphQLObjectType({
name: 'Foo',
fields: {
niceName: {
type: GraphQLString,
resolve: ({badName}) => badName,
unresolve: (root, value) => {
root.badName = value
delete root.niceName
}
}
},
},
})
Right now, to do this, you need to manually traverse the input arguments to apply the transformations where needed.
bali182, victorandree, WestleyArgentum, schickling, akaNightmare and 3 more