How to use the graphql-sequelize.typeMapper.toGraphQL function in graphql-sequelize

To help you get started, we’ve selected a few graphql-sequelize examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github almost-full-stack / sequelize-graphql-schema / src / graphql-sequelize / attributeFields.js View on Github external
if (options.only) {
      if (typeof options.only === 'function' && !options.only(key)) return memo;
      if (Array.isArray(options.only) && options.only.indexOf(key)) return memo;
    }

    const attribute = Model.rawAttributes[key];

    if (options.map) {
      if (typeof options.map === 'function') {
        key = options.map(key) || key;
      } else {
        key = options.map[key] || key;
      }
    }

    const _type = typeMapper.toGraphQL(attribute.type, Model.sequelize.constructor);

    memo[key] = {
      type: _type
    };

    if (memo[key].type instanceof GraphQLEnumType) {
      const typeName = `${Model.name}${key}EnumType`;

      /*
      Cache enum types to prevent duplicate type name error
      when calling attributeFields multiple times on the same model
      */

      if (cache[typeName]) {
        memo[key].type = cache[typeName];
      } else {