Skip to content

Support resolve on Input types #747

@wmertens

Description

@wmertens

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:

  1. re-packing/mapping fields:
const Foo = new GraphQLObjectType({
  name: 'Foo',
  fields: {
  	items: {
  		type: new GraphQLList(GraphQLString),
  		resolve: ({items}) => items.split(','),
  		unresolve: (_, items) => items.join(','),
  	},
       },
   })
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions