{"id":13880915,"url":"https://github.com/aerogear/graphql-metadata","last_synced_at":"2025-10-02T08:30:46.883Z","repository":{"id":56295310,"uuid":"234543027","full_name":"aerogear/graphql-metadata","owner":"aerogear","description":"Annotate your graphql schema with lightweight directives","archived":true,"fork":false,"pushed_at":"2023-04-09T14:38:33.000Z","size":171,"stargazers_count":28,"open_issues_count":4,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-17T22:16:23.323Z","etag":null,"topics":["annotations","graphql","graphql-schema","hacktoberfest"],"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/aerogear.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2020-01-17T12:23:08.000Z","updated_at":"2023-04-17T15:12:53.000Z","dependencies_parsed_at":"2024-01-13T21:11:13.898Z","dependency_job_id":null,"html_url":"https://github.com/aerogear/graphql-metadata","commit_stats":{"total_commits":80,"total_committers":7,"mean_commits":"11.428571428571429","dds":0.625,"last_synced_commit":"b0d98e67e2197b507290e70c967f77c35aabbe58"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aerogear%2Fgraphql-metadata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aerogear%2Fgraphql-metadata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aerogear%2Fgraphql-metadata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aerogear%2Fgraphql-metadata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aerogear","download_url":"https://codeload.github.com/aerogear/graphql-metadata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234957753,"owners_count":18913343,"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":["annotations","graphql","graphql-schema","hacktoberfest"],"created_at":"2024-08-06T08:03:39.018Z","updated_at":"2025-10-02T08:30:41.565Z","avatar_url":"https://github.com/aerogear.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# graphql-metadata\n\nAttach metadata to your GraphQL schema using directive like syntax. \n\nLibrary supoports following formats:\n\n- (**DEPRECATED**) Annotations: Group of elements with common namespace. For example `@db.length: 200`\n- Marker: Single instance (key) with multiple values. For example `@db length:200`\n- Metadata: Directive-like config. For example `@db(length: 200, columns: ['id', 'name'])`\n\n## Installation\n\n```bash\nnpm i graphql-metadata\n```\n\n## Usage\n\n### Marker parsing\n\nMarkers using different syntax for elements that do not support grouping.\nFor example `@marker true` etc.\n\nUsage: \n```js\nconst result = parseMarker('db', `\n  This is a description\n  @db length:200, unique: true \n`)\n```\n\nNo value usage:\n\n```js\nconst result = parseMarker('db', `\n  This is a description\n  @db\n`)\n```\n\n### Metadata parsing\n\nMetadata uses the same syntax as GraphQL directives.\n\nUsage: \n\n```js\nconst field: GraphQLField\u003cany,any\u003e = {\n  ...,\n  description: `@db(length:200, \n      unique: true, \n      columns: ['id', 'name']\n      description: 'Some description'\n    )`\n}\nconst result = parseMetadata('db', field)\n\n// Returns:\n{\n  length:200, \n  unique: true, \n  columns: ['id', 'name']\n  description: 'Some description'\n}\n```\n\nNo value usage:\n\n```js\nconst field: GraphQLField\u003cany,any\u003e = {\n  ...,\n  description: '@db',\n}\nconst result = parseMetadata('db', field)\n\n// Returns true\n```\n\nOr with a string:\n\n```js\nconst result = parseMetadata('db', '@db(name: \"users\")')\n```\n\n### [DEPRECATED] 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-metadata')\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-metadata')\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\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-metadata')\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%2Faerogear%2Fgraphql-metadata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faerogear%2Fgraphql-metadata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faerogear%2Fgraphql-metadata/lists"}