Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jcoreio/graphql-sequelize-extra

Package Overview
Dependencies
Maintainers
13
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jcoreio/graphql-sequelize-extra

some missing pieces of the graphql-sequelize bridge

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
Maintainers
13
Weekly downloads
 
Created
Source

@jcoreio/graphql-sequelize-extra

CircleCI Coverage Status semantic-release Commitizen friendly npm version

some missing pieces of the graphql-sequelize bridge

Installation

npm install --save @jcoreio/graphql-sequelize-extra

API

associationFields(model, options)

const { associationFields } = require('@jcoreio/graphql-sequelize-extra')

Creates GraphQL fields for the given sequelize model's associations.

Arguments

model: Class<Sequelize.Model<any>>
options: Object
options.getType: (model: Class<Sequelize.Model<any>>) => Object (required)

Gets the GraphQL type for the given sequelize model.

options.getArgs: (model: Class<Sequelize.Model<any>>) => Object (optional)

Gets the GraphQL args for the given sequelize model.

options.getResolver: (model: Class<Sequelize.Model<any>>, association: Sequelize.Association) => Function (optional)

Gets the GraphQL resolve function for the given sequelize model and association.

Returns

A plain object of GraphQL fields for the given model's associations.

Advice

You should use associationFields within a fields thunk since it some types it needs would fail to be defined if there are circular associations:

const { models } = sequelize

function getType(model) {
  return types[model.name]
}

const types = mapValues(
  models,
  (model) =>
    new graphql.GraphQLObjectType({
      name: model.name,
      fields: () => ({
        ...attributeFields(model),
        ...associationFields(model, { getType }),
      }),
    })
)

If you have circular associations, you should use some form of nested GraphQL query attack prevention.

Keywords

FAQs

Package last updated on 01 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc