{"id":13727196,"url":"https://github.com/charlypoly/graphql-to-json-schema","last_synced_at":"2025-04-12T23:32:49.905Z","repository":{"id":40775215,"uuid":"135441790","full_name":"charlypoly/graphql-to-json-schema","owner":"charlypoly","description":"GraphQL Schema to JSON Schema","archived":false,"fork":false,"pushed_at":"2025-04-09T19:33:46.000Z","size":778,"stargazers_count":216,"open_issues_count":25,"forks_count":27,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-09T20:33:51.126Z","etag":null,"topics":["graphql","json-schema","nodejs","typescript"],"latest_commit_sha":null,"homepage":null,"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/charlypoly.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-30T12:48:10.000Z","updated_at":"2025-04-03T20:39:10.000Z","dependencies_parsed_at":"2023-12-30T03:28:02.068Z","dependency_job_id":"67c40929-bc2a-4b65-ba39-b1ba9b7b14bf","html_url":"https://github.com/charlypoly/graphql-to-json-schema","commit_stats":{"total_commits":122,"total_committers":9,"mean_commits":"13.555555555555555","dds":0.540983606557377,"last_synced_commit":"2d04043b8a992dae994744e21010bb1d81bf3192"},"previous_names":["wittydeveloper/graphql-to-json-schema"],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlypoly%2Fgraphql-to-json-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlypoly%2Fgraphql-to-json-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlypoly%2Fgraphql-to-json-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/charlypoly%2Fgraphql-to-json-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/charlypoly","download_url":"https://codeload.github.com/charlypoly/graphql-to-json-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"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":["graphql","json-schema","nodejs","typescript"],"created_at":"2024-08-03T01:03:43.737Z","updated_at":"2025-04-12T23:32:49.883Z","avatar_url":"https://github.com/charlypoly.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# GraphQL Schema to JSON Schema [![npm version](https://badge.fury.io/js/graphql-2-json-schema.svg)](https://badge.fury.io/js/graphql-2-json-schema)\n\n`graphql-2-json-schema` package\n\n-----------\n\nTransform a GraphQL Schema introspection file to a valid JSON Schema.\n\n## Usage\n\n```ts\nimport {\n    graphqlSync,\n    getIntrospectionQuery,\n    IntrospectionQuery\n} from 'graphql';\n\nimport { fromIntrospectionQuery } from 'graphql-2-json-schema';\n\nconst options = {\n  // Whether or not to ignore GraphQL internals that are probably not relevant\n  // to documentation generation.\n  // Defaults to `true`\n  ignoreInternals: true,\n  // Whether or not to properly represent GraphQL Lists with Nullable elements\n  // as type \"array\" with items being an \"anyOf\" that includes the possible\n  // type and a \"null\" type.\n  // Defaults to `false` for backwards compatibility, but in future versions\n  // the effect of `true` is likely going to be the default and only way. It is\n  // highly recommended that new implementations set this value to `true`.\n  nullableArrayItems: true,\n  // Indicates how to define the `ID` scalar as part of a JSON Schema. Valid options\n  // are `string`, `number`, or `both`. Defaults to `string`\n  idTypeMapping: 'string'\n}\n\n// schema is your GraphQL schema.\nconst introspection = graphqlSync(schema, getIntrospectionQuery()).data as IntrospectionQuery;\n\nconst jsonSchema = fromIntrospectionQuery(introspection, options);\n```\n\n## Example\n\n### Input\n\n```graphql\n  type Todo {\n      id: ID!\n      name: String!\n      completed: Boolean\n      color: Color\n\n      \"A field that requires an argument\"\n      colors(\n        filter: [Color!]!\n      ): [Color!]!\n  }\n\n  type SimpleTodo {\n    id: ID!\n    name: String!\n  }\n\n  union TodoUnion = Todo | SimpleTodo\n\n  input TodoInputType {\n      name: String!\n      completed: Boolean\n      color: Color=RED\n  }\n\n  enum Color {\n      \"Red color\"\n      RED\n      \"Green color\"\n      GREEN\n  }\n\n  type Query {\n      \"A Query with 1 required argument and 1 optional argument\"\n      todo(\n        id: ID!,\n        \"A default value of false\"\n        isCompleted: Boolean=false\n      ): Todo\n\n      \"Returns a list (or null) that can contain null values\"\n      todos(\n        \"Required argument that is a list that cannot contain null values\"\n        ids: [String!]!\n      ): [Todo]\n  }\n\n  type Mutation {\n      \"A Mutation with 1 required argument\"\n      create_todo(\n        todo: TodoInputType!\n      ): Todo!\n\n      \"A Mutation with 2 required arguments\"\n      update_todo(\n        id: ID!,\n        data: TodoInputType!\n      ): Todo!\n\n      \"Returns a list (or null) that can contain null values\"\n      update_todos(\n        ids: [String!]!\n        data: TodoInputType!\n      ): [Todo]\n  }\n```\n\n### Output\n\n```js\n// Output is from call to fromIntrospectionQuery with the following options:\nconst options = { nullableArrayItems: true }\n\n{\n  '$schema': 'http://json-schema.org/draft-06/schema#',\n  properties: {\n    Query: {\n      type: 'object',\n      properties: {\n        todo: {\n          description: 'A Query with 1 required argument and 1 optional argument',\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/Todo' },\n            arguments: {\n              type: 'object',\n              properties: {\n                id: { '$ref': '#/definitions/ID' },\n                isCompleted: {\n                  description: 'A default value of false',\n                  '$ref': '#/definitions/Boolean',\n                  default: false\n                }\n              },\n              required: [ 'id' ]\n            }\n          },\n          required: []\n        },\n        todos: {\n          description: 'Returns a list (or null) that can contain null values',\n          type: 'object',\n          properties: {\n            return: {\n              type: 'array',\n              items: {\n                anyOf: [ { '$ref': '#/definitions/Todo' }, { type: 'null' } ]\n              }\n            },\n            arguments: {\n              type: 'object',\n              properties: {\n                ids: {\n                  description: 'Required argument that is a list that cannot contain null values',\n                  type: 'array',\n                  items: { '$ref': '#/definitions/String' }\n                }\n              },\n              required: [ 'ids' ]\n            }\n          },\n          required: []\n        }\n      },\n      required: []\n    },\n    Mutation: {\n      type: 'object',\n      properties: {\n        create_todo: {\n          description: 'A Mutation with 1 required argument',\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/Todo' },\n            arguments: {\n              type: 'object',\n              properties: { todo: { '$ref': '#/definitions/TodoInputType' } },\n              required: [ 'todo' ]\n            }\n          },\n          required: []\n        },\n        update_todo: {\n          description: 'A Mutation with 2 required arguments',\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/Todo' },\n            arguments: {\n              type: 'object',\n              properties: {\n                id: { '$ref': '#/definitions/ID' },\n                data: { '$ref': '#/definitions/TodoInputType' }\n              },\n              required: [ 'id', 'data' ]\n            }\n          },\n          required: []\n        },\n        update_todos: {\n          description: 'Returns a list (or null) that can contain null values',\n          type: 'object',\n          properties: {\n            return: {\n              type: 'array',\n              items: {\n                anyOf: [ { '$ref': '#/definitions/Todo' }, { type: 'null' } ]\n              }\n            },\n            arguments: {\n              type: 'object',\n              properties: {\n                ids: {\n                  type: 'array',\n                  items: { '$ref': '#/definitions/String' }\n                },\n                data: { '$ref': '#/definitions/TodoInputType' }\n              },\n              required: [ 'ids', 'data' ]\n            }\n          },\n          required: []\n        }\n      },\n      required: []\n    }\n  },\n  definitions: {\n    Todo: {\n      type: 'object',\n      properties: {\n        id: {\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/ID' },\n            arguments: { type: 'object', properties: {}, required: [] }\n          },\n          required: []\n        },\n        name: {\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/String' },\n            arguments: { type: 'object', properties: {}, required: [] }\n          },\n          required: []\n        },\n        completed: {\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/Boolean' },\n            arguments: { type: 'object', properties: {}, required: [] }\n          },\n          required: []\n        },\n        color: {\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/Color' },\n            arguments: { type: 'object', properties: {}, required: [] }\n          },\n          required: []\n        },\n        colors: {\n          description: 'A field that requires an argument',\n          type: 'object',\n          properties: {\n            return: { type: 'array', items: { '$ref': '#/definitions/Color' } },\n            arguments: {\n              type: 'object',\n              properties: {\n                filter: {\n                  type: 'array',\n                  items: { '$ref': '#/definitions/Color' }\n                }\n              },\n              required: [ 'filter' ]\n            }\n          },\n          required: []\n        }\n      },\n      required: [ 'id', 'name', 'colors' ]\n    },\n    ID: {\n      description: 'The `ID` scalar type represents a unique identifier, often used to refetch an object or as key for a cache. The ID type appears in a JSON response as a String; however, it is not intended to be human-readable. When expected as an input type, any string (such as `\"4\"`) or integer (such as `4`) input value will be accepted as an ID.',\n      type: 'string',\n      title: 'ID'\n    },\n    SimpleTodo: {\n      type: 'object',\n      properties: {\n        id: {\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/ID' },\n            arguments: { type: 'object', properties: {}, required: [] }\n          },\n          required: []\n        },\n        name: {\n          type: 'object',\n          properties: {\n            return: { '$ref': '#/definitions/String' },\n            arguments: { type: 'object', properties: {}, required: [] }\n          },\n          required: []\n        }\n      },\n      required: [ 'id', 'name' ]\n    },\n    TodoUnion: {\n      oneOf: [\n        { '$ref': '#/definitions/Todo' },\n        { '$ref': '#/definitions/SimpleTodo' }\n      ]\n    },\n    TodoInputType: {\n      type: 'object',\n      properties: {\n        name: { '$ref': '#/definitions/String' },\n        completed: { '$ref': '#/definitions/Boolean' },\n        color: { '$ref': '#/definitions/Color', default: 'RED' }\n      },\n      required: [ 'name' ]\n    },\n    Color: {\n      type: 'string',\n      anyOf: [\n        {\n          description: 'Red color',\n          enum: [ 'RED' ],\n          title: 'Red color'\n        },\n        {\n          description: 'Green color',\n          enum: [ 'GREEN' ],\n          title: 'Green color'\n        }\n      ]\n    },\n    String: {\n      description: 'The `String` scalar type represents textual data, represented as UTF-8 character sequences. The String type is most often used by GraphQL to represent free-form human-readable text.',\n      type: 'string',\n      title: 'String'\n    },\n    Boolean: {\n      description: 'The `Boolean` scalar type represents `true` or `false`.',\n      type: 'boolean',\n      title: 'Boolean'\n    }\n  }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlypoly%2Fgraphql-to-json-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcharlypoly%2Fgraphql-to-json-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcharlypoly%2Fgraphql-to-json-schema/lists"}