{"id":16227776,"url":"https://github.com/akryum/graphql-annotations","last_synced_at":"2025-03-19T13:31:13.542Z","repository":{"id":48272823,"uuid":"168151091","full_name":"Akryum/graphql-annotations","owner":"Akryum","description":"Annotate a GraphQL schema","archived":false,"fork":false,"pushed_at":"2021-08-03T19:19:26.000Z","size":576,"stargazers_count":17,"open_issues_count":14,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T18:57:03.997Z","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/Akryum.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"Akryum"}},"created_at":"2019-01-29T12:28:21.000Z","updated_at":"2022-01-09T11:24:32.000Z","dependencies_parsed_at":"2022-08-24T14:38:29.029Z","dependency_job_id":null,"html_url":"https://github.com/Akryum/graphql-annotations","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/Akryum%2Fgraphql-annotations","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akryum%2Fgraphql-annotations/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akryum%2Fgraphql-annotations/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Akryum%2Fgraphql-annotations/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Akryum","download_url":"https://codeload.github.com/Akryum/graphql-annotations/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243989726,"owners_count":20379648,"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":[],"created_at":"2024-10-10T12:53:50.037Z","updated_at":"2025-03-19T13:31:13.282Z","avatar_url":"https://github.com/Akryum.png","language":"JavaScript","funding_links":["https://github.com/sponsors/Akryum","https://www.patreon.com/akryum"],"categories":[],"sub_categories":[],"readme":"# graphql-annotations\n\n[![circleci](https://img.shields.io/circleci/project/github/Akryum/graphql-annotations/master.svg)](https://circleci.com/gh/Akryum/graphql-annotations)\n\nAnnotate a GraphQL schema\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.patreon.com/akryum\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://c5.patreon.com/external/logo/become_a_patron_button.png\" alt=\"Become a Patreon\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Sponsors\n\n### Gold\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.sumcumo.com/en/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://cdn.discordapp.com/attachments/258614093362102272/570728242399674380/logo-sumcumo.png\" alt=\"sum.cumo logo\" width=\"400px\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n### Silver\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://vueschool.io/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://vueschool.io/img/logo/vueschool_logo_multicolor.svg\" alt=\"VueSchool logo\" width=\"200px\"\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://www.vuemastery.com/\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://cdn.discordapp.com/attachments/258614093362102272/557267759130607630/Vue-Mastery-Big.png\" alt=\"Vue Mastery logo\" width=\"200px\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n### Bronze\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://vuetifyjs.com\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://cdn.discordapp.com/attachments/537832759985700914/537832771691872267/Horizontal_Logo_-_Dark.png\" width=\"100\"\u003e\n  \u003c/a\u003e\n\n  \u003ca href=\"https://www.frontenddeveloperlove.com/\" target=\"_blank\" title=\"Frontend Developer Love\"\u003e\n    \u003cimg src=\"https://cdn.discordapp.com/attachments/258614093362102272/557267744249085953/frontend_love-logo.png\" width=\"56\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n## Installation\n\n```bash\nnpm i graphql-annotations\n```\n\n## Usage\n\n### Annotations parsing\n\nHere is a very basic example with a `namespace` (here `'db'`) and a `description` that needs to be parsed:\n\n```js\nconst { parseAnnotations } = require('graphql-annotations')\n\nconst result = parseAnnotations('db', `\n  This is a description\n  @db.length: 200\n  @db.foo: 'bar'\n  @db.unique\n  @db.index: { name: 'foo', type: 'string' }\n`)\n\nconsole.log(result)\n```\n\nThis will output an object containing the annotations:\n\n```js\n{\n  length: 200,\n  foo: 'bar',\n  unique: true,\n  index: { name: 'foo', type: 'string' }\n}\n```\n\nIn a GraphQL schema, you can use the `description` property on `GraphQLObjectType`, `GraphQLField`...\n\n```js\nconst { parseAnnotations } = require('graphql-annotations')\nconst { buildSchema, isObjectType } = require('graphql')\n\nconst schema = buildSchema(`\n  \"\"\"\n  @db.table: 'users'\n  \"\"\"\n  type User {\n    \"\"\"\n    @db.primary\n    \"\"\"\n    id: ID!\n  }\n`)\n\nconst typeMap = schema.getTypeMap()\nfor (const key in typeMap) {\n  const type = typeMap[key]\n  // Tables\n  if (isObjectType(type)) {\n    const typeAnnotations = parseAnnotations('db', type.description)\n    console.log(type.name, typeAnnotations)\n    const fields = type.getFields()\n    for (const key in fields) {\n      const field = fields[key]\n      const fieldAnnotations = parseAnnotations('db', field.description)\n      console.log(field.name, fieldAnnotations)\n    }\n  }\n}\n```\n\nWhich will output:\n\n```js\nUser { table: 'users' }\nid { primary: true }\n```\n\n### Strip annotations\n\nSometimes it will be helpful to strip the annotations from the description. For example, you may not want to display them in a GraphQL schema explorer.\n\n```js\nconst { stripAnnotations } = require('graphql-annotations')\n\nconst result = stripAnnotations('db', `\n  This is a description\n  @db.length: 200\n  @db.foo: 'bar'\n  @db.unique\n  @db.index: { name: 'foo', type: 'string' }\n`)\n\nconsole.log(result)\n```\n\nThe result will be:\n\n```js\n`\n  This is a description\n`\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakryum%2Fgraphql-annotations","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakryum%2Fgraphql-annotations","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakryum%2Fgraphql-annotations/lists"}