{"id":22382390,"url":"https://github.com/jcoreio/graphql-sequelize-extra","last_synced_at":"2025-03-26T19:40:47.550Z","repository":{"id":33941821,"uuid":"114719552","full_name":"jcoreio/graphql-sequelize-extra","owner":"jcoreio","description":"some missing pieces of the graphql-sequelize bridge","archived":false,"fork":false,"pushed_at":"2023-01-06T01:56:56.000Z","size":3846,"stargazers_count":0,"open_issues_count":18,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-18T11:45:23.678Z","etag":null,"topics":["es2015"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jcoreio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-19T04:35:29.000Z","updated_at":"2021-01-01T05:13:26.000Z","dependencies_parsed_at":"2023-01-15T03:45:56.075Z","dependency_job_id":null,"html_url":"https://github.com/jcoreio/graphql-sequelize-extra","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fgraphql-sequelize-extra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fgraphql-sequelize-extra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fgraphql-sequelize-extra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jcoreio%2Fgraphql-sequelize-extra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jcoreio","download_url":"https://codeload.github.com/jcoreio/graphql-sequelize-extra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245726710,"owners_count":20662544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["es2015"],"created_at":"2024-12-05T00:12:48.750Z","updated_at":"2025-03-26T19:40:47.523Z","avatar_url":"https://github.com/jcoreio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @jcoreio/graphql-sequelize-extra\n\n[![CircleCI](https://circleci.com/gh/jcoreio/graphql-sequelize-extra.svg?style=svg)](https://circleci.com/gh/jcoreio/graphql-sequelize-extra)\n[![Coverage Status](https://codecov.io/gh/jcoreio/graphql-sequelize-extra/branch/master/graph/badge.svg)](https://codecov.io/gh/jcoreio/graphql-sequelize-extra)\n[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)\n[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg)](http://commitizen.github.io/cz-cli/)\n[![npm version](https://badge.fury.io/js/%40jcoreio%2Fgraphql-sequelize-extra.svg)](https://badge.fury.io/js/%40jcoreio%2Fgraphql-sequelize-extra)\n\nsome missing pieces of the graphql-sequelize bridge\n\n# Installation\n\n```sh\nnpm install --save @jcoreio/graphql-sequelize-extra\n```\n\n# API\n\n## `associationFields(model, options)`\n\n```js\nconst { associationFields } = require('@jcoreio/graphql-sequelize-extra')\n```\n\nCreates GraphQL fields for the given sequelize `model`'s `associations`.\n\n### Arguments\n\n#### `model: Class\u003cSequelize.Model\u003cany\u003e\u003e`\n\n#### `options: Object`\n\n##### `options.getType: (model: Class\u003cSequelize.Model\u003cany\u003e\u003e) =\u003e Object` (required)\n\nGets the GraphQL type for the given sequelize model.\n\n##### `options.getArgs: (model: Class\u003cSequelize.Model\u003cany\u003e\u003e) =\u003e Object` (optional)\n\nGets the GraphQL args for the given sequelize model.\n\n##### `options.getResolver: (model: Class\u003cSequelize.Model\u003cany\u003e\u003e, association: Sequelize.Association) =\u003e Function` (optional)\n\nGets the GraphQL `resolve` function for the given sequelize model and association.\n\n### Returns\n\nA plain object of GraphQL fields for the given `model`'s\n`associations`.\n\n### Advice\n\nYou should use `associationFields` within a `fields` thunk since it some\ntypes it needs would fail to be defined if there are circular\nassociations:\n\n```js\nconst { models } = sequelize\n\nfunction getType(model) {\n  return types[model.name]\n}\n\nconst types = mapValues(\n  models,\n  (model) =\u003e\n    new graphql.GraphQLObjectType({\n      name: model.name,\n      fields: () =\u003e ({\n        ...attributeFields(model),\n        ...associationFields(model, { getType }),\n      }),\n    })\n)\n```\n\nIf you have circular associations, you should [use some form of\nnested GraphQL query attack prevention](https://stackoverflow.com/questions/37337466/how-do-you-prevent-nested-attack-on-graphql-apollo-server).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fgraphql-sequelize-extra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjcoreio%2Fgraphql-sequelize-extra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjcoreio%2Fgraphql-sequelize-extra/lists"}