{"id":15660386,"url":"https://github.com/timmikeladze/graphql-crud","last_synced_at":"2025-04-30T13:40:43.216Z","repository":{"id":37752121,"uuid":"124469517","full_name":"TimMikeladze/graphql-crud","owner":"TimMikeladze","description":"GraphQL schema directives to generate CRUD queries, mutations and resolvers which are automatically connected to a database.","archived":false,"fork":false,"pushed_at":"2022-12-08T18:33:37.000Z","size":1080,"stargazers_count":20,"open_issues_count":56,"forks_count":7,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-20T08:08:29.554Z","etag":null,"topics":["crud","database","directives","graphql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/TimMikeladze.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-03-09T01:24:37.000Z","updated_at":"2023-05-26T00:19:44.000Z","dependencies_parsed_at":"2023-01-25T15:31:23.547Z","dependency_job_id":null,"html_url":"https://github.com/TimMikeladze/graphql-crud","commit_stats":null,"previous_names":["intelight/graphql-crud"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fgraphql-crud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fgraphql-crud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fgraphql-crud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TimMikeladze%2Fgraphql-crud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TimMikeladze","download_url":"https://codeload.github.com/TimMikeladze/graphql-crud/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251713223,"owners_count":21631505,"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":["crud","database","directives","graphql"],"created_at":"2024-10-03T13:21:25.694Z","updated_at":"2025-04-30T13:40:43.165Z","avatar_url":"https://github.com/TimMikeladze.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql-crud\n\n[![CircleCI](https://circleci.com/gh/Intelight/graphql-crud.svg?style=svg)](https://circleci.com/gh/Intelight/graphql-crud)\n\n**Note: This package is under active development.**\n\nGraphQL schema directives to generate CRUD queries, mutations and resolvers which are automatically connected to a database.\n\n**Supported databases:**\n\n- Mongo\n\n_Database of your choice missing? Adding one is easy  - implement the [Store](https://github.com/Intelight/graphql-crud/blob/master/packages/graphql-crud/src/Store.ts) interface._\n\n**Available directives:**\n\n- `@model` - Generates queries, mutations and resolvers for the annotated type.\n\n## Getting started\n\n1. Install core package: `npm install graphql-crud` or `yarn add graphql-crud`.\n2. Install a store package:\n    - Mongo: `npm install graphql-crud-mongo` or `yarn add graphql-crud-mongo`.\n3. Define your schema and annotate it with directives.\n4. Use `makeExecutableSchema` to generate the schema.\n5. Instantiate and assign your store to `directives.model.store` on the GraphQL `context`.\n\n```javascript\nimport { makeExecutableSchema } from 'graphql-tools';\nimport { execute } from 'graphql';\nimport gql from 'graphql-tag';\nimport crud from 'graphql-crud';\nimport MongoStore from 'graphql-crud-mongo';\nimport typeDefs from './typeDefs';\n\nconst typeDefs = `\n\ntype Author @model {\n  name: String!\n  books: [Book]\n  favoriteBook: Book\n}\n\ntype Book @model {\n  name: String!\n  authors: [Author]\n}\n\ntype Query {\n  _: Boolean\n}\n\ntype Mutation {\n  _: Boolean\n}\n\n`\n\nconst schema = makeExecutableSchema({\n  typeDefs,\n  schemaDirectives: {\n    ...crud\n  },\n});\n\nconst context = {\n  directives: {\n    model: {\n      store: new MongoStore({ connection: 'mongodb://localhost/my-database' }),\n    },\n  },\n};\n\nexecute(\n  schema,\n  gql`\n  mutation {\n    createAuthor(data: {\n      name:\"Leo Tolstoy\"\n    }) {\n      id\n      name\n    }\n  }\n  `\n  null,\n  context\n);\n```\n\nThe above example will generate the following schema with functioning resolvers.\n\n```graphql\n\"type Author {\n  name: String\n  books: [Book]\n  id: ID\n}\n\ninput AuthorInputType {\n  name: String\n  books: [BookInputType]\n  id: ID\n}\n\ntype Book {\n  name: String\n  authors: [Author]\n  id: ID\n}\n\ninput BookInputType {\n  name: String\n  authors: [AuthorInputType]\n  id: ID\n}\n\ntype Mutation {\n  _: Boolean\n  createAuthor(data: AuthorInputType): Author\n  updateAuthor(data: UpdateAuthorInputType, where: UpdateAuthorInputType, upsert: Boolean): Boolean\n  removeAuthor(where: AuthorInputType): Boolean\n  createBook(data: BookInputType): Book\n  updateBook(data: UpdateBookInputType, where: UpdateBookInputType, upsert: Boolean): Boolean\n  removeBook(where: BookInputType): Boolean\n}\n\ntype Query {\n  _: Boolean\n  author(where: AuthorInputType): Author\n  authors(where: AuthorInputType): [Author]\n  book(where: BookInputType): Book\n  books(where: BookInputType): [Book]\n}\n\ninput UpdateAuthorInputType {\n  name: String\n  books: [UpdateBookInputType]\n  id: ID\n}\n\ninput UpdateBookInputType {\n  name: String\n  authors: [UpdateAuthorInputType]\n  id: ID\n}\n```\n\n## Running the examples\n\nIn the repo's root run the following:\n1. `docker-compose up -d` to start dependent databases.\n1. `npm install` or `yarn install`\n\nIn `examples/simple` run the following:\n\n1. `npm install; npm start` or `yarn install; yarn start`\n1. Navigate to http://localhost:3000/graphiql\n\n\n## Getting started for development\n\n1. `docker-compose up -d` to start database dependencies for testing and the example.\n1. `npm install` or `yarn install`.\n1. `npm run link:packages` or `yarn link:packages`.\n1. `npm run build:watch` or `yarn build:watch`\n1. Write code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimmikeladze%2Fgraphql-crud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftimmikeladze%2Fgraphql-crud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftimmikeladze%2Fgraphql-crud/lists"}