{"id":19204592,"url":"https://github.com/walmartlabs/json-to-simple-graphql-schema","last_synced_at":"2025-04-04T13:11:59.648Z","repository":{"id":34136245,"uuid":"168766752","full_name":"walmartlabs/json-to-simple-graphql-schema","owner":"walmartlabs","description":"Transforms JSON input into a GraphQL schema","archived":false,"fork":false,"pushed_at":"2023-01-07T04:07:34.000Z","size":1750,"stargazers_count":287,"open_issues_count":4,"forks_count":39,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-28T12:09:23.298Z","etag":null,"topics":["graphql","javascript","json"],"latest_commit_sha":null,"homepage":"https://walmartlabs.github.io/json-to-simple-graphql-schema/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/walmartlabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-01T22:11:24.000Z","updated_at":"2025-03-19T17:41:51.000Z","dependencies_parsed_at":"2023-01-15T04:50:11.227Z","dependency_job_id":null,"html_url":"https://github.com/walmartlabs/json-to-simple-graphql-schema","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walmartlabs%2Fjson-to-simple-graphql-schema","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walmartlabs%2Fjson-to-simple-graphql-schema/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walmartlabs%2Fjson-to-simple-graphql-schema/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/walmartlabs%2Fjson-to-simple-graphql-schema/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/walmartlabs","download_url":"https://codeload.github.com/walmartlabs/json-to-simple-graphql-schema/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247182401,"owners_count":20897381,"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","javascript","json"],"created_at":"2024-11-09T13:08:53.194Z","updated_at":"2025-04-04T13:11:59.631Z","avatar_url":"https://github.com/walmartlabs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## json-to-simple-graphql-schema\n\nTransforms JSON input into a GraphQL schema.\n[Try it here](https://walmartlabs.github.io/json-to-simple-graphql-schema/)\n\n### Why would I use this?\n\nLet's say you want to use an existing REST API in a GraphQL service and expose the data that API provides. You'll need to expose that data in a GraphQL schema. Without this tool, you'll have to slog through the JSON response and manually extract and convert the relevant types to GraphQL schema types. This tool attempts to provide an automated reasonable first-pass at that effort.\n\n### Installation:\n\nFor use as a command-line app use `npx` :) If you'd really like to install, you can do:\n\n```bash\nnpm i -g @walmartlabs/json-to-simple-graphql-schema\n```\n\nFor use in a project:\n\n```bash\nnpm i @walmartlabs/json-to-simple-graphql-schema\n```\n\n### Command Line Usage:\n\nPipe in some JSON. Here's a cURL JSON response piped in to this app:\n\n```bash\ncurl \"https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.json?accessType=DOWNLOAD\" \\\n| npx @walmartlabs/json-to-simple-graphql-schema\n```\n\n\u003e You'll still need to rename the resulting main Type in the schema, unless you like `AutogeneratedMainType` :)\n\nOr pipe in some JSON from a JSON file.\n\n```bash\ncurl https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.json?accessType=DOWNLOAD \u003e input.json\n\ncat input.json | npx json-to-simple-graphql-schema \u003e output.graphql\n```\n\nOptional parameters:\n\n- baseType = \"AutogeneratedMainType\"\n- prefix = \"\"\n\n```bash\ncurl https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.json?accessType=DOWNLOAD \u003e input.json\n\ncat input.json | npx json-to-simple-graphql-schema --baseType BaseType --prefix Prefix \u003e output.graphql\n```\n\n### Usage in front-end JS:\n\n```javascript\nimport { jsonToSchema } from \"@walmartlabs/json-to-simple-graphql-schema/lib\";\n\nconst schema = jsonToSchema({ jsonInput: '{\"name\": \"Test\"}' });\nconsole.log(schema.value);\n```\n\nIf you need more guidance, have a look at [the source for our simple web-ui](./web-ui).\n\n### Example output:\n\nGiven this JSON:\n\n```json\n{\n  \"id\": \"some-id-0\",\n  \"name\": \"A fun object\",\n  \"subType\": {\n    \"id\": \"some-id-1\",\n    \"name\": \"A fun sub-type\"\n  }\n}\n```\n\nThis app will send this to stdout:\n\n```\ntype SubType {\n  id: String\n  name: String,\n}\ntype AutogeneratedMainType {\n  id: String\n  name: String\n  subType: SubType\n}\n```\n\n### Fun features: duplicate removal\n\nConsider this JSON with 2 `color` types:\n\n```json\n{\n  \"id\": \"some-id-0\",\n  \"name\": \"A fun object\",\n  \"color\": {\n    \"id\": \"color-id-1\",\n    \"name\": \"Test color\"\n  },\n  \"subType\": {\n    \"id\": \"some-id-1\",\n    \"name\": \"A fun sub-type\",\n    \"color\": {\n      \"id\": \"color-id-1\",\n      \"name\": \"Test color\",\n      \"hex\": \"#ff0000\"\n    }\n  }\n}\n```\n\nWhen piped to this app, the following schema is produced:\n\n```\ntype Color {\n  id: String\n  name: String\n  hex: String,\n}\ntype SubType {\n  id: String\n  name: String\n  color: Color,\n}\ntype AutogeneratedMainType {\n  id: String\n  name: String\n  subType: SubType\n  color: Color\n}\n```\n\nIt kept the `Color` type with more fields.\n\n### Fun features: calls out possible duplicates\n\nConsider this JSON with two types containing identical fields:\n\n```json\n{\n  \"id\": \"some-id-0\",\n  \"name\": \"A fun object\",\n  \"color\": {\n    \"id\": \"color-id-1\",\n    \"name\": \"Test color\"\n  },\n  \"favoriteColor\": {\n    \"id\": \"color-id-1\",\n    \"name\": \"Test color\"\n  }\n}\n```\n\nWhen piped to this app, the following schema is produced:\n\n```\ntype FavoriteColor {\n  id: String\n  name: String\n}\n\ntype Color {\n  id: String\n  name: String\n}\n\ntype AutogeneratedMainType {\n  id: String\n  name: String\n  favoriteColor: FavoriteColor\n  color: Color\n}\n\n# Types with identical fields:\n# FavoriteColor Color\n```\n\nIt called out the two types with identical fields.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalmartlabs%2Fjson-to-simple-graphql-schema","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwalmartlabs%2Fjson-to-simple-graphql-schema","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwalmartlabs%2Fjson-to-simple-graphql-schema/lists"}