{"id":15471601,"url":"https://github.com/sammarks/objection-graphql","last_synced_at":"2026-02-08T22:30:59.395Z","repository":{"id":34296203,"uuid":"174200926","full_name":"sammarks/objection-graphql","owner":"sammarks","description":"GraphQL helpers for quickly crafting resolvers with Objection.JS","archived":false,"fork":false,"pushed_at":"2022-04-28T19:22:31.000Z","size":144,"stargazers_count":0,"open_issues_count":9,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-03T20:13:54.282Z","etag":null,"topics":[],"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/sammarks.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-06T18:44:13.000Z","updated_at":"2019-11-25T20:10:04.000Z","dependencies_parsed_at":"2022-08-08T00:15:41.007Z","dependency_job_id":null,"html_url":"https://github.com/sammarks/objection-graphql","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/sammarks/objection-graphql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fobjection-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fobjection-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fobjection-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fobjection-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sammarks","download_url":"https://codeload.github.com/sammarks/objection-graphql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sammarks%2Fobjection-graphql/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269663432,"owners_count":24455807,"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","status":"online","status_checked_at":"2025-08-09T02:00:10.424Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-10-02T02:20:53.770Z","updated_at":"2026-02-08T22:30:59.346Z","avatar_url":"https://github.com/sammarks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![][header-image]\n\n[![CircleCI][circleci-image]][circleci-url]\n[![NPM version][npm-version]][npm-url]\n[![NPM downloads][npm-downloads]][npm-url]\n![License][license]\n![Issues][issues]\n\n`@sammarks/objection-graphql` is a set of helper methods for quickly crafting resolvers with GraphQL and Objection.JS. \n\n## Get Started\n\n```sh\nnpm install @sammarks/objection-graphql\nyarn add @sammarks/objection-graphql\n```\n\nOn each of your models, decorate them with `withGraphQLSupport`\n\n```js\nimport { withGraphQLSupport } from '@sammarks/objection-graphql'\n\n@withGraphQLSupport()\nexport default class User extends Model {\n  static tableName = 'users'\n  static get relationMappings () {\n    return {\n      posts: {\n        modelClass: Post,\n        relation: Model.HasManyRelation,\n        join: {\n          from: 'users.id',\n          to: 'posts.user_id'\n        }\n      }\n    }\n  }\n}\n```\n\nNow, in your GraphQL resolvers:\n\n```js\nimport { getResolver, nodeResolver } from '@sammarks/objection-graphql'\nimport User from './models/User'\n\nconst resolvers = {\n  Node: nodeResolver,\n  User: getResolver(User)\n}\n```\n\nAnd then the following GraphQL schema will automatically be supported.\n\n```graphql\nenum OrderDirection {\n  ASC\n  DESC\n}\n\ntype User {\n\n  # Standard user fields...\n  id: ID!\n  firstName: String!\n  lastName: String!\n  \n  # Relationships!\n  posts(\n    first: Int = 10,\n    after: String,\n    orderBy: String = \"id\",\n    orderDirection: OrderDirection = ASC\n  ): PostsConnection!\n  \n}\n```\n\nSee [objection-graphql-relay](https://github.com/sammarks/objection-graphql-relay) for some more information. \n\n## Function Reference\n\n### getResolver(ObjectionModel model)\n\nAutomatically generates a resolver for the passed Objection.JS model. Currently does not support\nextra customization.\n\nWill automatically generate resolvers for single and multiple relationships. See the source code\nfor `orderedPagedRelationQuery()` for more information.\n\n### nodeResolver\n\nThis is just a pretty standard GraphQL Node resolver. See the code sample above for how to use\nthis. It just takes the constructor name of the Model and uses that to determine the GraphQL type\n(so make sure those are the same!)\n\n### withGraphQLSupport()\n\nDecorator for adding helper methods required for the automatic connection creator inside `getResolver()`. \nReturns a function that accepts the model to decorate. There are currently no configuration options. \n\n## Features\n\n- Automatically generates GraphQL resolvers based on Objection.JS models.\n- Includes support for many-to-many relationships and one-to-many relationships with GraphQL Relay\n  support out of the box.\n- Relationship connections automatically support ordering by specific fields.\n- Includes a basic GraphQL Node resolver for convenience.\n\n[header-image]: https://raw.githubusercontent.com/sammarks/art/master/objection-graphql/header.jpg\n[circleci-image]: https://img.shields.io/circleci/project/github/sammarks/objection-graphql.svg\n[circleci-url]: https://circleci.com/gh/sammarks/objection-graphql/tree/master\n[npm-version]: https://img.shields.io/npm/v/@sammarks/objection-graphql.svg\n[npm-downloads]: https://img.shields.io/npm/dm/@sammarks/objection-graphql.svg\n[npm-url]: https://www.npmjs.com/package/@sammarks/objection-graphql\n[license]: https://img.shields.io/github/license/sammarks/objection-graphql.svg\n[issues]: https://img.shields.io/github/issues/sammarks/objection-graphql.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsammarks%2Fobjection-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsammarks%2Fobjection-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsammarks%2Fobjection-graphql/lists"}