diff --git a/src/type/custom/to-input-object.js b/src/type/custom/to-input-object.js index ff19b93..2c57aa3 100644 --- a/src/type/custom/to-input-object.js +++ b/src/type/custom/to-input-object.js @@ -7,14 +7,24 @@ import { GraphQLScalarType, GraphQLInputObjectType, GraphQLEnumType, - GraphQLID, + GraphQLID } from 'graphql'; +const cachedTypes = {}; + function createInputObject(type) { - return new GraphQLInputObjectType({ - name: `${type.name}Input`, - fields: filterFields(type.getFields(), (field) => (!field.noInputObject)), // eslint-disable-line - }); + const typeName = `${type.name}Input`; + + if (!cachedTypes.hasOwnProperty(typeName)) { + cachedTypes[typeName] = new GraphQLInputObjectType({ + name: typeName, + fields: {} + }); + cachedTypes[typeName]._typeConfig.fields = + () => filterFields(type.getFields(), (field) => (!field.noInputObject)); // eslint-disable-line + } + + return cachedTypes[typeName]; } function filterFields(obj, filter) {