{"bugs":{"url":"https://github.com/aerogear/graphql-metadata/issues"},"dist":{"shasum":"2d0b52cad3f91f53a59726f386834c266945540e","tarball":"https://registry.npmjs.org/graphql-metadata/-/graphql-metadata-0.7.3-dev1.tgz","fileCount":38,"integrity":"sha512-Wd0MjwJhFdoMgRDzmtMYL5Z0dPgRDAPPfrTcPp3SbKQ3tutcDkfFHCu0iaxkGAiPYItCksZnUA/2R/50aMuu8Q==","signatures":[{"sig":"MEYCIQCkMF0VqLkF9SO2VlCyBIQMUQWWKN5OohHtpZCtIo3kyAIhAPoFqRSWvjggk+whDmGUGnUOlj+TB6J1T+dAM1i/oG48","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":203191,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfH+X7CRA9TVsSAnZWagAAbowP/1ez8LppWPU80vn69OQZ\njTGXP/OPz2jxkLLUTlWredOi9mvMqBDpAMw0nBeGUSXh4xkyjzlacQT+WSYs\nsX1gAG8g9zDbHR9FJFKpO6mK3wdAI0RhCEzB4qHihTis4HXGAyYUnEuyltY6\n9JXCGWhjm3416PKb8WVXfRQe8ENBuC/SCboJAKrltHeYMHRQYby8740ljQ4b\n8yDNUWM2MTQQ3fn5TCz7CAQwjkt0/NpHfOt/wH55kD4rsIBiUcdKgVmbTNVo\ns0GKtYO7oKtct1vJLtmA+IlSNetzXK4YJwHfxRRFHXQu2XFHslcSmTIz6Cpi\nnmfWIfW+/zByL+C/r6PnPh4MmyVGPXwemgP6rUCcQe2FB6f+MncAXXv+BBTS\nFeO+ghBp/7QVtY61y56Khfct7TrcR2U5U7HNF901pugcivVAQlidDPTXPFaO\nfY+6a7spT/3hvozlQmgUVlE3wkS1724Wm6HlJVnLVQfsZcdZ+qQNLZgAtoW9\nAU7JrQpXZyTJ/9jrXlaTH1CY6G2kJRRUiMcDC8Dpox0Ae+MaNPYWbuxZXLOt\nNv53/qX10VTc7RFuERzSBe48UqIlaSAEN4Vo6ZP4igyFTo6GRs4s/WHD3kVH\nPfV4z5rZUTt4luA/ZOLHK+Or+tyLFZ8Z+u6bypSVRBkSQp3TmHjjtTw917gp\npB3d\r\n=U8JK\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/index.js","name":"graphql-metadata","types":"dist/index.d.ts","author":{"name":"Enda Phelan","email":"ephelan@redhat.com"},"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<any,any> = {\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<any,any> = {\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","gitHead":"87d1e39e5bb77c33dc7451b81a1420552a609c38","license":"MIT","scripts":{"lint":"eslint ./src/**/*.ts","test":"jest","build":"tsc -b","clean":"rimraf dist","watch":"tsc -w","test:all":"yarn run lint && yarn run test && yarn run test:types","test:types":"tsc","prepublishOnly":"yarn run test:all"},"_npmUser":{"name":"ephelan","email":"ephelan@redhat.com"},"homepage":"https://github.com/aerogear/graphql-metadata/#readme","repository":{"url":"git+https://github.com/aerogear/graphql-metadata.git","type":"git"},"_npmVersion":"6.14.4","description":"Annotate a GraphQL Schema","directories":{},"maintainers":[{"name":"wtrocki","email":"wtrocki@redhat.com"}],"_nodeVersion":"12.16.1","dependencies":{"chalk":"4.0.0","safe-eval":"0.4.1"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"26.0.1","eslint":"^5.12.1","rimraf":"3.0.2","graphql":"15.0.0","ts-jest":"26.0.0","typescript":"^3.9.3","@types/jest":"^25.2.3","eslint-plugin-node":"^8.0.1","eslint-plugin-import":"^2.20.2","@typescript-eslint/parser":"2.34.0","@typescript-eslint/eslint-plugin":"2.34.0"},"peerDependencies":{"graphql":"^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"},"_npmOperationalInternal":{"tmp":"tmp/graphql-metadata_0.7.3-dev1_1595926010894_0.0880738638893428","host":"s3://npm-registry-packages"},"_id":"graphql-metadata@0.7.3-dev1","version":"0.7.3-dev1"}