How to use dataloader-sequelize - 9 common examples

To help you get started, we’ve selected a few dataloader-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 opencollective / opencollective-api / server / graphql / loaders / index.js View on Github external
export const loaders = req => {
  const cache = {};
  const context = createContext(sequelize);

  context.loaders.Comment = generateCommentsLoader(req, cache);
  context.loaders.Conversation = generateConversationLoaders(req, cache);

  /** *** Collective *****/

  // Collective - ChildCollectives
  context.loaders.Collective.childCollectives = new DataLoader(parentIds =>
    models.Collective.findAll({
      where: { ParentCollectiveId: { [Op.in]: parentIds }, type: CollectiveType.COLLECTIVE },
    }).then(collectives => sortResults(parentIds, collectives, 'ParentCollectiveId', [])),
  );

  // Collective - Balance
  context.loaders.Collective.balance = new DataLoader(ids =>
    models.Transaction.findAll({
github birkir / prime / packages / prime-core / src / routes / external / index.ts View on Github external
context: async ({ req }) => {
      try {
        const cookie = String(req.headers.cookie);
        const cookies = new Map(cookie.split(';').map(n => n.trim().split('=')) as any);

        if (req.headers['x-prime-version-id'] && req.headers['x-prime-version-id'].length === 36) {
          cookies.set('prime.versionId', req.headers['x-prime-version-id']);
        }

        const context: IContext = {
          settings,
          sequelizeDataLoader: createContext(sequelize),
          public: settings.accessType === 'public',
          published: true,
          contentReleaseId: null,
          versionId: null,
          entryId: null,
        };

        debug('context.public %o', context.public);

        if (cookies.has('prime.versionId')) {
          const versionId = cookies.get('prime.versionId') as string;
          debug('context.versionId %o', versionId);
          if (versionId.length === 36) {
            const entry = await ContentEntry.findOne({ where: { versionId } });
            if (entry) {
              context.entryId = entry.id;
github almost-full-stack / sequelize-graphql-schema / src / sequelize-graphql-schema.js View on Github external
const generateSchema = (models, types, context, Sequelize) => {
  Models = models
  Sequelize = models.Sequelize || Sequelize

  if (options.dataloader) dataloaderContext = createContext(models.sequelize)
  if (Sequelize) {
    Sequelize.useCLS(sequelizeNamespace)
  } else {
    console.warn('Sequelize not found at Models.Sequelize or not passed as argument. Automatic tranasctions for mutations are disabled.')
    options.transactionedMutations = false
  }

  let availableModels = {}
  for (let modelName in models) {
    models[modelName].graphql = models[modelName].graphql || defaultModelGraphqlOptions
    models[modelName].graphql.attributes = Object.assign({}, defaultModelGraphqlOptions.attributes, models[modelName].graphql.attributes)
    models[modelName].graphql = Object.assign({}, defaultModelGraphqlOptions, models[modelName].graphql || {})
    if (options.exclude.indexOf(modelName) === -1) {
      availableModels[modelName] = models[modelName]
    }
  }
github Vheissu / aurelia-graphql-apollo / server / index.js View on Github external
context: ({ req }) => {
        return {
            [EXPECTED_OPTIONS_KEY]: createContext(db.sequelize),
            user: req.user,
        }
    }
});
github shfshanyue / apollo-server-starter / db / index.ts View on Github external
get [EXPECTED_OPTIONS_KEY] () {
    const key = 'SequelizeContext'
    if (cache.get(key)) {
      return cache.get(key)
    }
    const context = createContext(sequelize)
    cache.set(key, context)
    return context
  }
}
github almost-full-stack / sequelize-graphql-schema / src / index.js View on Github external
function generateSchema(models, context) {

  assert(models.Sequelize, 'Sequelize not found as models.Sequelize.');
  assert(models.sequelize, 'sequelize instance not found as models.sequelize.');

  if (options.dataloader) {
    dataloaderContext = createContext(models.sequelize);
    options.dataloaderContext = dataloaderContext;
  }

  options.Sequelize = models.Sequelize;
  options.sequelize = models.sequelize;

  options.Sequelize.useCLS(sequelizeNamespace);

  const { generateModelTypes } = GenerateTypes(options);
  const generateQueries = GenerateQueries(options);
  const generateMutations = GenerateMutations(options);
  const modelsIncluded = {};

  for (const modelName in models) {

    const model = models[modelName];
github brianschardt / node_graphql_apollo_template / src / app.ts View on Github external
context: ({ req }) => {
        return {
            [EXPECTED_OPTIONS_KEY]: createContext(sequelize),
            user: req.user,
        };
    }
});
github almost-full-stack / sequelize-graphql-schema / dist / sequelize-graphql-schema.js View on Github external
var attributeFields = require('./graphql-sequelize/attributeFields');

var sequelizeConnection = relay.sequelizeConnection;

var camelCase = require('camelcase');

var remoteSchema = require('./remoteSchema');

var _require4 = require('graphql-request'),
    GraphQLClient = _require4.GraphQLClient;

var _ = require('lodash');

var _require5 = require('dataloader-sequelize'),
    createContext = _require5.createContext,
    EXPECTED_OPTIONS_KEY = _require5.EXPECTED_OPTIONS_KEY,
    resetCache = _require5.resetCache;

var TRANSACTION_NAMESPACE = 'sequelize-graphql-schema';

var cls = require('cls-hooked');

var uuid = require('uuid/v4');

var sequelizeNamespace = cls.createNamespace(TRANSACTION_NAMESPACE);
var dataloaderContext;
var options = {
  exclude: [],
  includeArguments: {},
  remote: {},
  dataloader: false,
  customTypes: [],
github almost-full-stack / sequelize-graphql-schema / dist / sequelize-graphql-schema.js View on Github external
var sequelizeConnection = relay.sequelizeConnection;

var camelCase = require('camelcase');

var remoteSchema = require('./remoteSchema');

var _require4 = require('graphql-request'),
    GraphQLClient = _require4.GraphQLClient;

var _ = require('lodash');

var _require5 = require('dataloader-sequelize'),
    createContext = _require5.createContext,
    EXPECTED_OPTIONS_KEY = _require5.EXPECTED_OPTIONS_KEY,
    resetCache = _require5.resetCache;

var TRANSACTION_NAMESPACE = 'sequelize-graphql-schema';

var cls = require('cls-hooked');

var uuid = require('uuid/v4');

var sequelizeNamespace = cls.createNamespace(TRANSACTION_NAMESPACE);
var dataloaderContext;
var options = {
  exclude: [],
  includeArguments: {},
  remote: {},
  dataloader: false,
  customTypes: [],
  transactionedMutations: true,

dataloader-sequelize

Batching and simplification of Sequelize with facebook/dataloader

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis