{"id":23991250,"url":"https://github.com/danomatic/sequelize-graphql","last_synced_at":"2025-02-25T05:17:10.766Z","repository":{"id":40727169,"uuid":"245006638","full_name":"danomatic/sequelize-graphql","owner":"danomatic","description":"Resolve GraphQL queries with a single SQL query","archived":false,"fork":false,"pushed_at":"2023-03-02T20:15:29.000Z","size":431,"stargazers_count":1,"open_issues_count":8,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-07T19:39:22.252Z","etag":null,"topics":["dataloader","graphql","sequelize","sequelize-orm","sql"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danomatic.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-04T21:22:21.000Z","updated_at":"2022-04-01T23:38:14.000Z","dependencies_parsed_at":"2025-01-07T19:39:01.191Z","dependency_job_id":"e5ac9a1c-90af-4f54-9e86-8068fe8cf3de","html_url":"https://github.com/danomatic/sequelize-graphql","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danomatic%2Fsequelize-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danomatic%2Fsequelize-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danomatic%2Fsequelize-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danomatic%2Fsequelize-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danomatic","download_url":"https://codeload.github.com/danomatic/sequelize-graphql/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240605841,"owners_count":19827985,"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":["dataloader","graphql","sequelize","sequelize-orm","sql"],"created_at":"2025-01-07T19:38:48.742Z","updated_at":"2025-02-25T05:17:10.746Z","avatar_url":"https://github.com/danomatic.png","language":"TypeScript","readme":"# Sequelize GraphQL\nThis is a simple set of helper functions that will recursively traverse a GraphQL query and create the optimal Sequelize `findAll` options for `include`, `where`, `attributes`, `limit`, and `orderBy`. A complex GraphQL query can often be resolved with a single SQL query, maximizing performance.\n\n## See Also\n* Sequelize Query Docs: https://sequelize.org/v5/manual/querying.html\n* Alternative approach without Sequelize: https://github.com/acarl005/join-monster\n* Facebook's DataLoader: https://github.com/graphql/dataloader\n\n## Example\n\n### SQL Schema\n```mysql\nCREATE TABLE `person`\n(\n  `id`              int(10) unsigned NOT NULL AUTO_INCREMENT,\n  `name`            varchar(255)   NOT NULL DEFAULT '',\n  `best_friend_id`  varchar(255)   NOT NULL DEFAULT '',\n  PRIMARY KEY (`id`),\n  CONSTRAINT `best_friend_fk`\n    FOREIGN KEY (`best_friend_id`)\n    REFERENCES `person` (`id`) ON DELETE SET NULL ON UPDATE CASCADE\n) ENGINE = InnoDB;\n```\n\n### GraphQL Schema\n```graphql\nenum OrderDirection {\n  ASC\n  DESC\n}\n\ninput ColumnOrder {\n  col: String,\n  dir: OrderDirection\n}\n\ntype Person {\n  id: Int\n  name: String\n  bestFriendId: Int\n  bestFriend: Person\n}\n\ntype Query {\n  people(where: JSON, orderBy: [ColumnOrder], limit: Int, offset: Int): [Person]\n}\n```\n\n### Sequelize Model\n```typescript\nimport {\n  Model,\n  Association,\n  DataTypes,\n  Sequelize\n} from \"sequelize\";\n\nexport class Person extends Model {\n  public id!: number;\n  public name!: string;\n  public bestFriendId!: number;\n  public readonly bestFriend!: Person;\n\n  public static associations: {\n    bestFriend: Association\u003cPerson, Person\u003e;\n  };\n}\n\nexport default (sequelize: Sequelize) =\u003e {\n  Person.init({\n    id: {\n      type: DataTypes.INTEGER.UNSIGNED,\n      primaryKey: true,\n      autoIncrement: true,\n      allowNull: false\n    },\n    name: DataTypes.STRING(255),\n    bestFriendId: DataTypes.INTEGER.UNSIGNED\n  }, {\n    underscored: true,\n    tableName: 'person',\n    sequelize: sequelize\n  });\n\n  return Person;\n};\n```\n\n### Resolver\n```typescript\nconst resolvers: IResolvers = {\n  Query: {\n    people: (source, args, context: GraphQLContext, info): Person[] =\u003e {\n      return context.db.Person.findAll(getSequelizeQuery(args, info, context.db.Person));\n    }\n  }\n};\n```\n\n### Query\n```graphql\nquery {\n  people {\n    id\n    name\n    bestFriend {\n      id\n      name\n      bestFriend {\n        id\n        name\n      }\n    }\n  }\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanomatic%2Fsequelize-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanomatic%2Fsequelize-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanomatic%2Fsequelize-graphql/lists"}