Can you make a GraphQL type both an input and output type?

Technology CommunityCategory: GraphQLCan you make a GraphQL type both an input and output type?
VietMX Staff asked 3 years ago

In the GraphQL spec, objects and input objects are distinct things. While an implementation might provide convenience code (see below) to create an object and a corresponding input object from a single definition, under the covers, the spec indicates that they’ll have to be separate things.

Consider:

const RelativeTemplate = name => {
  return {
    name: name,
    fields: () => ({
      name: { type: GraphQLString },
      reference: { type: GraphQLString }
    })
  };
};

const RelativeType = {
  input: new GraphQLInputObjectType(RelativeTemplate("RelativeInput")),
  output: new GraphQLObjectType(RelativeTemplate("RelativeOutput"))
};