{"_id":"@gnd/jsonschema2graphql","_rev":"1-a2a907f7d005ce2af73794cbd2311109","name":"@gnd/jsonschema2graphql","dist-tags":{"latest":"1.0.15"},"versions":{"1.0.15":{"name":"@gnd/jsonschema2graphql","version":"1.0.15","description":"Converts JSON schema to GraphQL types","repository":{"type":"git","url":"git+https://github.com/HerbCaudill/jsonschema2graphql.git"},"homepage":"https://github.com/HerbCaudill/jsonschema2graphql#readme","bugs":{"url":"https://github.com/HerbCaudill/jsonschema2graphql/issues"},"author":{"name":"Herb Caudill","email":"herb@devresults.com"},"license":"MIT","keywords":["json-schema","graphql"],"main":"build/index.js","types":"build/index.d.ts","scripts":{"build":"tsc -p tsconfig.json","clean":"trash build","fix:prettier":"prettier \"src/**/*.ts\" --write","fix:tslint":"tslint --fix --project .","fix":"run-s fix:*","prepublishOnly":"run-s clean build test","preview":"package-preview ","reset":"git clean -dfx && git reset --hard && yarn install","lint":"tslint --project . && prettier \"src/**/*.ts\" --list-different","test":"jest","watch":"run-s clean build && run-p \"build -- -w\" \"test --watch\""},"engines":{"node":">=8.9"},"dependencies":{"ajv":"^6.5.4","camelcase":"^5.0.0","graphql":"14.0.2","lodash":"^4.17.11","pluralize":"^7.0.0","ramda":"^0.25.0","uppercamelcase":"^3.0.0"},"devDependencies":{"@types/camelcase":"^4.1.0","@types/fs-extra":"^5.0.4","@types/graphql":"^14.0.1","@types/jest":"^23.3.1","@types/jest-diff":"^20.0.0","@types/jest-matcher-utils":"^21.0.1","@types/json-schema":"^7.0.1","@types/lodash":"^4.14.116","@types/pluralize":"^0.0.29","@types/ramda":"^0.25.38","@types/uppercamelcase":"^3.0.0","babel-jest":"^23.6.0","fs-extra":"^7.0.0","gh-pages":"^2.0.0","jest":"22.4.2","jest-diff":"^23.6.0","jest-matcher-utils":"^23.6.0","npm-run-all":"^4.1.5","opn-cli":"^3.1.0","package-preview":"^1.0.6","prettier":"^1.14.3","tmp-promise":"^1.0.5","trash-cli":"^1.4.0","ts-jest":"22.0.1","tslint":"^5.11.0","tslint-config-prettier":"^1.15.0","typescript":"^3.0.3"},"jest":{"moduleFileExtensions":["ts","tsx","js","jsx","json","node"],"roots":["<rootDir>/src","<rootDir>/test"],"testEnvironment":"node","testMatch":["**/?(*.)test.ts"],"transform":{"^.+\\.tsx?$":"ts-jest"},"setupTestFrameworkScriptFile":"<rootDir>/test/matchers/index.ts"},"prettier":{"printWidth":120,"semi":false,"singleQuote":true,"trailingComma":"es5"},"gitHead":"278e37e7716511d2f11a1cb555d88e88d045f020","_id":"@gnd/jsonschema2graphql@1.0.15","_npmVersion":"6.4.1","_nodeVersion":"8.12.0","_npmUser":{"name":"gnidan","email":"nick@gnidan.org"},"dist":{"integrity":"sha512-dcUCGh9ZKTCNbs79rlFQq9gMLLZu2LHWkqIeEWfO8Z7wjwTvhSZTe3E2/h0/laCEWoyp14gBVTJoeRn6qiEPLQ==","shasum":"d5abd7ec425874ac9d93b6ba2faaf74d015ae294","tarball":"https://registry.npmjs.org/@gnd/jsonschema2graphql/-/jsonschema2graphql-1.0.15.tgz","fileCount":16,"unpackedSize":29105,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcSOT4CRA9TVsSAnZWagAAhusP/R9T0YvCjix6UCd1f6op\nuQU3hF/a/SpGgM07UAtmPHessZYwIN+bhZOTgzF9ILCR4rrSaquszzOsScqY\nNL11Al7ZXsXXw4iNPvBu1bKvjwVIEWKKzuMgdWMpdmbSL4u/6CVQZyJK5+uT\nVHZsjnTXemReU04KGqLKVcqLs3Y/P3rAu2q1y14LnyVWdCbwJ3QCr0HytgDs\n82QhHuPQS9P1ZpeQQfeKJcZyjfl+0eF5G15VKnhw2/7w0vIuU57AwrgRbjsy\nRaewus524NHcAn1kKuwxPWTLwjCkHUTe4tHuedbEzHhCZR4vZow32Bg1cvMP\nLkyPq6Y14rWlWULLg4l3oBusiDbYtigBl0tK6GQ8r6O6vsnwM1BZuqVLjF0A\n2TXs9yMH/eWrO7+sarDKhYj3SHlCeL0Ar/OWwjgDoHZ6gkzBH6XyueBDNbDW\ntIk0GG/+U6fEWThDTbgP6+7501dqvPqtpZH10wyr3QA/+SHVcAXZUxFHupcT\nja0A5nzvN0AouDCYF89f/JVqfdfZbzVFuVn8NbItGhOuKTWzGjXzcoWaVT81\nYX2BAgchcRRc4eAtROmh4fomDDjdC0+ROupw1l9UFgAEeERI7WPyq4rlg7VV\nrIq6/skvZylZ7XcKHx8w/ZZc6EIa84OJmumUk+3EdIme3IAaziwc3Q6hGnQy\nbKcy\r\n=+hec\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCkq9OAZqz7cNWnNfscsp53CZEfJPBbk8qJDqidrdYTMwIgIlNlkU2aYA7sfPa5V04RpKCx6YD5bzYwfGJRlFKzLH8="}]},"maintainers":[{"name":"gnidan","email":"nick@gnidan.org"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/jsonschema2graphql_1.0.15_1548281079889_0.21221980518733985"},"_hasShrinkwrap":false}},"time":{"created":"2019-01-23T22:04:39.428Z","1.0.15":"2019-01-23T22:04:40.030Z","modified":"2022-04-05T14:47:16.221Z"},"maintainers":[{"name":"gnidan","email":"nick@gnidan.org"}],"description":"Converts JSON schema to GraphQL types","homepage":"https://github.com/HerbCaudill/jsonschema2graphql#readme","keywords":["json-schema","graphql"],"repository":{"type":"git","url":"git+https://github.com/HerbCaudill/jsonschema2graphql.git"},"author":{"name":"Herb Caudill","email":"herb@devresults.com"},"bugs":{"url":"https://github.com/HerbCaudill/jsonschema2graphql/issues"},"license":"MIT","readme":"![logo](./img/logo.png)\n\n# JSON Schema to GraphQL converter\n\nThis library exports a single function, `convert`, which converts one or more [JSON schemas](https://json-schema.org/) to a [GraphQL schema]().\n\n## Installation\n\nInstall with yarn:\n\n```\nyarn add jsonschema2graphql\n```\n\n## Usage\n\nYou can convert a schema expressed as an object literal:\n\n```js\nimport { printSchema } from 'graphql'\nimport convert from 'jsonschema2graphql'\n\nconst jsonSchema = {\n  $id: 'person',\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string',\n    },\n    age: {\n      type: 'integer',\n    },\n  },\n}\n\nconst schema = convert({ jsonSchema })\n\nconsole.log(printSchema(schema))\n```\n\nOutput\n\n```graphql\ntype Person {\n  name: String\n  age: Int\n}\ntype Query {\n  people: [Person]\n}\n```\n\nAlternatively, you can provide the schema as JSON text.\n\n```js\nconst schema = convert({\n  jsonSchema: `{\n    \"$id\": \"person\",\n    \"type\": \"object\",\n    \"properties\": {\n      \"name\": {\n        \"type\": \"string\"\n      },\n      \"age\": {\n        \"type\": \"integer\"\n      }\n    }\n  }`,\n})\n```\n\nThis will generate the same result as above.\n\nTo generate more than one type, provide an array of JSON schemas in either object or text form.\n\n```js\nconst orange = {\n  $id: 'Orange',\n  type: 'object',\n  properties: {\n    color: {\n      type: 'string',\n    },\n  },\n}\n\nconst apple = {\n  $id: 'Apple',\n  type: 'object',\n  properties: {\n    color: { type: 'string' },\n    bestFriend: {\n      $ref: 'Orange', // <-- reference foreign type using $ref\n    },\n  },\n}\n\nconst schema = convert({ jsonSchema: [orange, apple] })\n```\n\nOutput\n\n```graphql\ntype Apple {\n  color: String\n  bestFriend: Orange\n}\ntype Orange {\n  color: String\n}\ntype Query {\n  oranges: [Orange]\n  apples: [Apple]\n}`\n```\n\n### Custom root types (`Query`, `Mutation`, `Subscription`)\n\nBy default, a `Query` type is added to the schema, with one field defined per type, returning an array of that type. So for example, if you have an `Person` type and a `Post` type, you'll get a `Query` type that looks like this:\n\n```graphql\ntype Query {\n  people: [Person]\n  posts: [Posts]\n}\n```\n\n(Note that the generated name for the field is automatically [pluralized](https://github.com/blakeembrey/pluralize).)\n\nBy default, no `Mutation` or `Subscription` types are created.\n\nTo create a custom `Query` type and to add `Mutation` and/or `Subscription` blocks, provide an `entryPoints` callback that takes a hash of GraphQL types and returns `Query`, `Mutation` (optional), and `Subscription` (optional) blocks. Each block consists of a hash of `GraphQLFieldConfig` objects.\n\n```js\nconst jsonSchema = [log, user, family]\n\nconst entryPoints = types => {\n  return {\n    query: new GraphQLObjectType({\n      name: 'Query',\n      fields: {\n        family: { type: types['Family'] },\n        user: {\n          type: types['User'],\n          args: {\n            email: { type: types['Email'] },\n          },\n        },\n      },\n    }),\n    mutation: new GraphQLObjectType({\n      name: 'Mutation',\n      fields: {\n        stop: { type: types['Log'] },\n      },\n    }),\n  }\n}\n\nconst schema = convert({ jsonSchema, entryPoints })\n```\n\nSee the GraphQL guide [\"Constructing Types\"](https://graphql.org/graphql-js/constructing-types/) for more on how to create GraphQL types programmatically.\n\nNote that any types that are not referenced directly or indirectly by your root types will be omitted from the final schema.\n\n## JSON schema feature support\n\n> **Note:** This package is designed for use with schemas compliant with [JSON Schema Draft 7](https://json-schema.org/specification.html).\n\nFor clarity, the following examples only show the converted types; the `Query` type is omitted from the output.\n\n### Basic types\n\nInput\n\n```js\n{\n  $id: 'Person',\n  type: 'object',\n  properties: {\n    name: { type: 'string' },\n    age: { type: 'integer' },\n    score: { type: 'number' },\n    isMyFriend: { type: 'boolean' },\n  },\n}\n```\n\nOutput\n\n```graphql\ntype Person {\n  name: String\n  age: Int\n  score: Float\n  isMyFriend: Boolean\n}\n```\n\n### Array types\n\nInput\n\n```js\nconst jsonSchema = {\n  $id: 'Person',\n  type: 'object',\n  properties: {\n    name: {\n      type: 'string',\n    },\n    luckyNumbers: {\n      type: 'array',\n      items: {\n        type: 'integer',\n      },\n    },\n    favoriteColors: {\n      type: 'array',\n      items: {\n        type: 'string',\n      },\n    },\n  },\n}\n```\n\nOutput\n\n```graphql\ntype Person {\n  name: String\n  luckyNumbers: [Int!]\n  favoriteColors: [String!]\n}\n```\n\n#### Enums\n\nInput\n\n```js\nconst jsonSchema = {\n  $id: 'Person',\n  type: 'object',\n  properties: {\n    height: {\n      type: 'string',\n      enum: ['tall', 'average', 'short'], // <-- enum\n    },\n  },\n}\n```\n\nOutput\n\n```graphql\ntype Person {\n  height: PersonHeight\n}\n\nenum PersonHeight {\n  tall\n  average\n  short\n}\n```\n\n#### Required fields\n\nInput\n\n```js\nconst jsonSchema = {\n  $id: 'Widget',\n  type: 'object',\n  properties: {\n    somethingRequired: { type: 'integer' },\n    somethingOptional: { type: 'integer' },\n    somethingElseRequired: { type: 'integer' },\n  },\n  required: ['somethingRequired', 'somethingElseRequired'],\n}\n```\n\nOutput\n\n```graphql\ntype Widget {\n  somethingRequired: Int!\n  somethingOptional: Int\n  somethingElseRequired: Int!\n}\n```\n\n#### Foreign references using `$ref`\n\nInput\n\n```js\nconst jsonSchema = {\n  {\n    $id: 'Orange',\n    type: 'object',\n    properties: {\n      color: {\n        type: 'string',\n      },\n    },\n  },\n  {\n    $id: 'Apple',\n    type: 'object',\n    properties: {\n      color: { type: 'string' },\n      bestFriend: {\n        $ref: 'Orange', // <-- reference foreign type using $ref\n      },\n    },\n  },\n]\n```\n\nOutput\n\n```graphql\ntype Apple {\n  color: String\n  bestFriend: Orange\n}\n\ntype Orange {\n  color: String\n}\n```\n\n#### Union types using `oneOf`\n\nInput\n\n```js\nconst jsonSchema = {\n  {\n    $id: 'Parent',\n    type: 'object',\n    properties: {\n      type: { type: 'string' },\n      name: { type: 'string' },\n    },\n  },\n  {\n    $id: 'Child',\n    type: 'object',\n    properties: {\n      type: { type: 'string' },\n      name: { type: 'string' },\n      parent: { $ref: 'Parent' },\n      bestFriend: { $ref: 'Person' },\n      friends: {\n        type: 'array',\n        items: { $ref: 'Person' },\n      },\n    },\n  },\n  {\n    $id: 'Person',\n    oneOf: [{ $ref: 'Parent' }, { $ref: 'Child' }],\n  },\n]\n```\n\nOutput\n\n```graphql\ntype Child {\n  type: String\n  name: String\n  parent: Parent\n  bestFriend: Person\n  friends: [Person!]\n}\n\ntype Parent {\n  type: String\n  name: String\n}\n\nunion Person = Parent | Child\n```\n\nProperties defined as `oneOf` with `if`/`then` are also supported. For example, this:\n\n```js\nconst jsonSchema = {\n  $id: 'Person',\n  oneOf: [\n    {\n      if: { properties: { type: { const: 'Parent' } } },\n      then: { $ref: 'Parent' },\n    },\n    {\n      if: { properties: { type: { const: 'Child' } } },\n      then: { $ref: 'Child' },\n    },\n  ],\n}\n```\n\ngenerates the same `union` type as above:\n\n```graphql\nunion Person = Parent | Child\n```\n\n#### Descriptions for types and fields\n\nInput\n\n```js\nconst jsonSchema = {\n  $id: 'person',\n  type: 'object',\n  description: 'An individual human being.',\n  properties: {\n    name: {\n      type: 'string',\n      description: 'The full name of the person.',\n    },\n    age: {\n      type: 'integer',\n      description: \"The elapsed time (in years) since the person's birth.\",\n    },\n  },\n}\n```\n\nOutput\n\n```graphql\n\"\"\"\nAn individual human being.\n\"\"\"\ntype Person {\n  \"\"\"\n  The full name of the person.\n  \"\"\"\n  name: String\n  \"\"\"\n  The elapsed time (in years) since the person's birth.\n  \"\"\"\n  age: Int\n}\n```\n\n### To do\n\nThe following features are not currently supported, but I'd like to add them for completeness. Pull requests are welcome.\n\n- [ ] Combining JSON schemas with `allOf`, `anyOf`, or `not`\n- [ ] Generating GraphQL input types\n\n---\n\n### Acknowledgements\n\nDerived from [json-schema-to-graphql-types](https://github.com/lifeomic/json-schema-to-graphql-types) by [Matt Lavin](https://github.com/mdlavin) (matt.lavin@gmail.com).\n\nBuilt with [typescript-starter](https://github.com/bitjson/typescript-starter) by [Jason Dreyzehner](https://github.com/bitjson) (github@bitjson.com).\n\nMIT License\n","readmeFilename":"README.md"}