src/types/generateType.js
function generateType(name, def) {
  // const def = _.find(getTypeDefs(), (o, n) => n === name);

  if (!name || !def) {
    return null;
  }

  // If def doesnt have {generated: false} prop, then it is
  // already a type. Hence return it as is.
  if (def.generated !== false) {
    return def;
  }

  def = _.clone(def);
  processIdField(name, def);

  if (def.meta.category === 'TYPE') {

    def.fields = () => generateTypeFields(def);

    if (def.meta.input === true) {
      return new GraphQLInputObjectType(def);
    }

    return new GraphQLObjectType(def);
  } else if (def.category === 'ENUM') {
    const values = {};
    _.forEach(def.values, (val) => { values[val] = { value: val }; });
    def.values = values;

    return new GraphQLEnumType(def);
  }
}
function generateType(name, def) {
  // const def = _.find(getTypeDefs(), (o, n) => n === name);

  if (!name || !def) {
    return null;
  }

  // If def doesnt have {generated: false} prop, then it is
  // already a type. Hence return it as is.
  if (def.generated !== false) {
    return def;
  }

  def = _.clone(def);
  processIdField(name, def);

  if (def.meta.category === 'TYPE') {

    def.fields = () => generateTypeFields(def);

    if (def.meta.input === true) {
      return new GraphQLInputObjectType(def);
    }

    return new GraphQLObjectType(def);
  } else if (def.category === 'ENUM') {
    const values = {};
    _.forEach(def.values, (val) => { values[val] = { value: val }; });
    def.values = values;

    return new GraphQLEnumType(def);
  }
}
function generateType ( name , def ) { // const def = _.find(getTypeDefs(), (o, n) => n === name); if ( ! name || ! def ) { return null ; } // If def doesnt have {generated: false} prop, then it is // already a type. Hence return it as is. if ( def . generated !== false ) { return def ; } def = _ . clone ( def ) ; processIdField ( name , def ) ; if ( def . meta . category === 'TYPE' ) { def . fields = ( ) => generateTypeFields ( def ) ; if ( def . meta . input === true ) { return new GraphQLInputObjectType ( def ) ; } return new GraphQLObjectType ( def ) ; } else if ( def . category === 'ENUM' ) { const values = { } ; _ . forEach ( def . values , ( val ) => { values [ val ] = { value : val } ; } ) ; def . values = values ; return new GraphQLEnumType ( def ) ; } }
Dynamically generate type based on the definition in typeDefs
@param {*} name
@param {*} def Type definition
Dynamically generate type based on the definition in typeDefs