How to use the graphql-sequelize.resolver 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 tomlagier / crypto-dca / api / models / coin / type.js View on Github external
localAmount: {
        type: new GraphQLNonNull(GraphQLString),
        description: 'Amount of coin held in local wallet'
      },
      exchangeAmount: {
        type: new GraphQLNonNull(GraphQLString),
        description: 'Amount of coin held in exchange wallet'
      },
      purchaseAmount: {
        type: new GraphQLNonNull(GraphQLString),
        description: 'Amount of coin waiting to be bought on exchange'
      },
      localWallet: {
        type: Wallet,
        description: 'Local wallet associated with coin',
        resolve: resolver(Coin.LocalWallet)
      },
      exchangeWallet: {
        type: Wallet,
        description: 'Wallet on exchange associated with coin',
        resolve: resolver(Coin.ExchangeWallet)
      },
      feeTolerance: {
        type: new GraphQLNonNull(GraphQLString),
        description: 'Maximum percentage of a transaction allowed to be lost in fees'
      },
      // transactions: {
      //   type: new GraphQLList(Transaction),
      //   description: 'Transactions associated with this coin'
      // }
    }
  }
github json-schema-faker / json-schema-sequelizer / lib / graphql.js View on Github external
return function resolver() {
      let _wrapper;

      try {
        const model = callback(modelName, arguments[1], arguments[2]);
        const key = `${model.sequelize.options.identifier}_${model.name}`;

        // avoid wrapping too much!
        if (!_cache[key]) {
          _wrapper = _cache[key] = graphqlSequelize.resolver(model);
        } else {
          _wrapper = _cache[key];
        }
      } catch (e) {
        throw new Error(`Unable to resolve(${modelName}). ${e.message}`);
      }

      return _wrapper.apply(null, arguments);
    };
  };
github tomlagier / crypto-dca / api / models / transaction / type.js View on Github external
startAmount: {
        type: new GraphQLNonNull(GraphQLString),
        description: 'The amount of startCoin spent'
      },
      endAmount: {
        type: new GraphQLNonNull(GraphQLString),
        description: 'The amount of endCoin received'
      },
      success: {
        type: new GraphQLNonNull(GraphQLBoolean),
        description: 'Whether the transaction was a success'
      },
      startWallet: {
        type: Wallet,
        description: 'Starting wallet',
        resolve: resolver(Transaction.StartWallet)
      },
      endWallet: {
        type: Wallet,
        description: 'Ending wallet',
        resolve: resolver(Transaction.EndWallet)
      },
      startCoin: {
        type: Coin,
        description: 'Starting coin',
        resolve: resolver(Transaction.StartCoin)
      },
      endCoin: {
        type: Coin,
        description: 'Ending coin',
        resolve: resolver(Transaction.EndCoin)
      },
github oughtinc / mosaic / server / lib / schema / index.ts View on Github external
function modelGraphQLFields(type: any, model: any) {
  return {
    type,
    args: { where: { type: GraphQLJSON } },
    resolve: resolver(model),
  };
}
github birkir / prime / packages / prime-core / src / routes / internal / index.ts View on Github external
opts.where = {
              [sequelize.Op.and]: [
                sequelize.where(sequelize.fn('lower', sequelize.col('name')), args.name.toLowerCase()),
              ],
            };
          }
          return opts;
        },
      }),
    },
    ContentTypeField: {
      type: contentTypeFieldType,
      args: {
        id: { type: new GraphQLNonNull(GraphQLID) },
      },
      resolve: resolver(ContentTypeField),
    },
    ContentEntry: {
      type: contentEntryType,
      args: {
        entryId: { type: GraphQLID },
        versionId: { type: GraphQLID },
        contentReleaseId: { type: GraphQLID },
        language: { type: GraphQLString },
      },
      resolve: resolver(ContentEntry, {
        before(opts, args, context) {
          opts.where = {
            entryId: args.entryId,
          };

          if (args.language) {
github bradleyboy / tuql / src / builders / schema.js View on Github external
return fields;
        },
      });

      types[key] = type;

      queries[formatFieldName(key)] = {
        type: new GraphQLList(type),
        args: defaultListArgs(model),
        resolve: resolver(model),
      };

      queries[singular(formatFieldName(key))] = {
        type,
        args: defaultArgs(model),
        resolve: resolver(model),
      };

      mutations[`create${type}`] = {
        type,
        args: makeCreateArgs(model),
        resolve: async (obj, values, info) => {
          const thing = await model.create(values);
          return thing;
        },
      };

      mutations[`update${type}`] = {
        type,
        args: makeUpdateArgs(model),
        resolve: async (obj, values, info) => {
          const pkKey = getPkFieldKey(model);
github almost-full-stack / sequelize-graphql-schema / src / sequelize-graphql-schema.js View on Github external
resolve: async (source, args, context, info) => {
            const whereClause = { [key]: { [Models.Sequelize.Op.in]: args[inputTypeName].map((input) => input[key]) } }

            await mutationResolver(models[inputTypeName], inputTypeName, source, args, context, info, 'update', null, hasBulkOptionEdit)

            return resolver(models[inputTypeName], { [EXPECTED_OPTIONS_KEY]: dataloaderContext })(source, whereClause, context, info)
          }
        }
github brianschardt / node_graphql_apollo_template / src / graphql / user / user.mutation.ts View on Github external
import { resolver as rs } from 'graphql-sequelize';
import { User } from '../../models';
import to from 'await-to-js';

export const Mutation = {
    createUser: rs(User, {
      before: async (findOptions, { data }) => {
        let err, user;
        [err, user] = await to(User.create(data) );
        if (err) {
          throw err;
        }
        findOptions.where = { id:user.id };
        return findOptions;
      },
      after: (user) => {
        user.login = true;
        return user;
      }
    }),
};
github birkir / prime / packages / prime-core / src / routes / internal / index.ts View on Github external
],
            ],
          };
          return options;
        },
        after(values) {
          return values.map(({ dataValues }) => ({
            ...dataValues,
          }));
        },
      }),
    },
    allContentEntries,
    allUsers: {
      type: new GraphQLList(userType),
      resolve: resolver(User, {
        async after(users) {
          return await Promise.all(
            users.map(async user => {
              user.roles = await acl.userRoles(user.id);
              return user;
            })
          );
        },
      }),
    },
    allWebhooks,
    allWebhookCalls,
    isContentTypeAvailable: {
      type: GraphQLBoolean,
      args: {
        name: { type: GraphQLString },
github almost-full-stack / sequelize-graphql-schema / src / sequelize-graphql-schema.js View on Github external
orderBy.push([clause.substring(8), 'DESC'])
        } else {
          orderBy.push([clause, 'ASC'])
        }
      })

      findOptions.order = orderBy
    }

    findOptions.paranoid = ((args.where && args.where.deletedAt && args.where.deletedAt.ne === null) || args.paranoid === false) ? false : model.options.paranoid
    return findOptions
  }

  const scope = Array.isArray(model.graphql.scopes) ? { method: [model.graphql.scopes[0], _.get(args, model.graphql.scopes[1], model.graphql.scopes[2] || null)] } : model.graphql.scopes

  const data = await resolver(model.scope(scope), {
    [EXPECTED_OPTIONS_KEY]: dataloaderContext,
    before
  })(source, args, context, info)

  if (model.graphql.extend.hasOwnProperty(type)) {
    return model.graphql.extend[type](data, source, args, context, info)
  }

  return data
}