{"id":47839,"library":"graphql-compose-json","title":"graphql-compose-json","description":"Plugin for `graphql-compose` that generates GraphQL types from JSON objects. Current stable version is 6.2.0. Release cadence is irregular; latest update in 2023. Key differentiators: automatic type inference from JSON fields, support for custom field resolvers, and dual output/input type generation. Requires peer dependency graphql-compose ^7–9. Ships TypeScript definitions. Actively maintained by the graphql-compose organization.","status":"active","version":"6.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/graphql-compose/graphql-compose-json","tags":["javascript","graphql","compose","rest","typescript"],"install":[{"cmd":"npm install graphql-compose-json","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-compose-json","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-compose-json","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required at version ^7.0.4 || ^8.0.0 || ^9.0.0","package":"graphql-compose","optional":false},{"reason":"Peer dependency for GraphQL runtime; not listed in package.json but required in README","package":"graphql","optional":false}],"imports":[{"note":"CommonJS require works but ESM is preferred. TypeScript included.","wrong":"const { composeWithJson } = require('graphql-compose-json')","symbol":"composeWithJson","correct":"import { composeWithJson } from 'graphql-compose-json'"},{"note":"Named export, not default export.","wrong":"import composeInputWithJson from 'graphql-compose-json'","symbol":"composeInputWithJson","correct":"import { composeInputWithJson } from 'graphql-compose-json'"},{"note":"graphql-compose-json does not have a default export; must use named exports.","wrong":"import gql from 'graphql-compose-json'","symbol":"default import","correct":"import gql from 'graphql-tag'"},{"note":"Type-only imports require `type` modifier to avoid runtime errors.","wrong":"import { ComposeWithJson } from 'graphql-compose-json'","symbol":"TypeScript type","correct":"import type { ComposeWithJson } from 'graphql-compose-json'"}],"quickstart":{"code":"import { composeWithJson, composeInputWithJson } from 'graphql-compose-json';\nimport { schemaComposer } from 'graphql-compose';\n\nconst restApiResponse = {\n  name: 'Anakin Skywalker',\n  birth_year: '41.9BBY',\n  gender: 'male',\n  mass: 77,\n  homeworld: 'https://swapi.co/api/planets/1/',\n  films: ['https://swapi.co/api/films/5/', 'https://swapi.co/api/films/4/', 'https://swapi.co/api/films/6/'],\n  species: ['https://swapi.co/api/species/1/'],\n  starships: ['https://swapi.co/api/starships/59/', 'https://swapi.co/api/starships/65/', 'https://swapi.co/api/starships/39/'],\n};\n\nconst PersonTC = composeWithJson('Person', restApiResponse);\nconst PersonGraphQLType = PersonTC.getType();\n\nconst PersonITC = composeInputWithJson('PersonInput', restApiResponse);\nconst PersonGraphQLInput = PersonITC.getType();\n\nschemaComposer.Query.addFields({ person: PersonTC });\nconst schema = schemaComposer.buildSchema();\nconsole.log(require('graphql').printSchema(schema));","lang":"typescript","description":"Demonstrates generating GraphQL output and input types from a JSON object using composeWithJson and composeInputWithJson, then adding to a query field."},"warnings":[{"fix":"Update field definitions from `field: () => 'Int'` to `field: () => 'Int!'` or `field: () => ({ type: 'Int', resolve: source => ... })`","message":"Breaking change in v6: The function signature for custom field resolvers changed. Earlier versions allowed direct function for type; now it must be a function returning a string with type or an object with type and resolve.","severity":"breaking","affected_versions":"5.x"},{"fix":"Upgrade graphql-compose to ^7.0.4 || ^8.0.0 || ^9.0.0","message":"Support for graphql-compose v6 and below is dropped; need at least v7.","severity":"deprecated","affected_versions":"6.x"},{"fix":"For nested objects, create separate types via composeWithJson and use field resolvers to reference them.","message":"Nested objects are NOT automatically resolved into GraphQL types; they remain as JSON scalar unless manually expanded using additional composeWithJson calls.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Ensure arrays contain homogeneous element types, or provide custom field config with a resolve function to transform data.","message":"Array fields with mixed types (e.g., array of strings and numbers) will cause errors at runtime.","severity":"gotcha","affected_versions":">=6.0.0"}],"env_vars":null,"search_vec":"'2023':29 '6.2.0':21 '7':54 '9':55 'activ':59 'automat':32 'cadenc':23 'compos':3,9,53,65,69 'current':17 'custom':40 'definit':58 'depend':50 'differenti':31 'dual':44 'field':37,41 'generat':11,47 'graphql':2,8,12,52,64,68 'graphql-compos':7,51,63 'graphql-compose-json':1 'infer':34 'irregular':25 'javascript':67 'json':4,15,36 'key':30 'latest':26 'maintain':60 'object':16 'organ':66 'output/input':45 'peer':49 'plugin':5 'releas':22 'requir':48 'resolv':42 'rest':70 'ship':56 'stabl':18 'support':38 'type':13,33,46 'typescript':57,71 'updat':27 'version':19","created_at":"2026-06-07T16:53:34.599318+00:00","updated_at":"2026-06-07T16:53:34.599318+00:00","problems":[{"fix":"npm install graphql-compose-json graphql-compose graphql","cause":"Package not installed or missing from node_modules.","error":"Cannot find module 'graphql-compose-json'"},{"fix":"Use `import { composeWithJson } from 'graphql-compose-json'`","cause":"Default import used instead of named import.","error":"TypeError: composeWithJson is not a function"},{"fix":"Use `mass: () => 'Int!'` in the response object to override type.","cause":"JSON numbers are inferred as Float by default; custom field config needed for Int.","error":"Field 'mass' must return type 'Int' but value is 77 (Float)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/graphql-compose/graphql-compose-json","github":"https://github.com/graphql-compose/graphql-compose-json","docs":null,"changelog":null,"pypi":null,"npm":"graphql-compose-json","openapi_spec":null,"status_page":null,"smithery":null,"categories":["development"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}