Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
composeWithJson
✓ import { composeWithJson } from 'graphql-compose-json'
✗ const { composeWithJson } = require('graphql-compose-json')
CommonJS require works but ESM is preferred. TypeScript included.
composeInputWithJson
✓ import { composeInputWithJson } from 'graphql-compose-json'
✗ import composeInputWithJson from 'graphql-compose-json'
Named export, not default export.
default import
✓ import gql from 'graphql-tag'
✗ import gql from 'graphql-compose-json'
graphql-compose-json does not have a default export; must use named exports.
TypeScript type
✓ import type { ComposeWithJson } from 'graphql-compose-json'
✗ import { ComposeWithJson } from 'graphql-compose-json'
Type-only imports require `type` modifier to avoid runtime errors.
Demonstrates generating GraphQL output and input types from a JSON object using composeWithJson and composeInputWithJson, then adding to a query field.
import { composeWithJson, composeInputWithJson } from 'graphql-compose-json';
import { schemaComposer } from 'graphql-compose';
const restApiResponse = {
name: 'Anakin Skywalker',
birth_year: '41.9BBY',
gender: 'male',
mass: 77,
homeworld: 'https://swapi.co/api/planets/1/',
films: ['https://swapi.co/api/films/5/', 'https://swapi.co/api/films/4/', 'https://swapi.co/api/films/6/'],
species: ['https://swapi.co/api/species/1/'],
starships: ['https://swapi.co/api/starships/59/', 'https://swapi.co/api/starships/65/', 'https://swapi.co/api/starships/39/'],
};
const PersonTC = composeWithJson('Person', restApiResponse);
const PersonGraphQLType = PersonTC.getType();
const PersonITC = composeInputWithJson('PersonInput', restApiResponse);
const PersonGraphQLInput = PersonITC.getType();
schemaComposer.Query.addFields({ person: PersonTC });
const schema = schemaComposer.buildSchema();
console.log(require('graphql').printSchema(schema));
Errors
Common errors & fixes
Cannot find module 'graphql-compose-json'
Package not installed or missing from node_modules.
fixnpm install graphql-compose-json graphql-compose graphql
TypeError: composeWithJson is not a function
Default import used instead of named import.
fixUse `import { composeWithJson } from 'graphql-compose-json'` Field 'mass' must return type 'Int' but value is 77 (Float)
JSON numbers are inferred as Float by default; custom field config needed for Int.
fixUse `mass: () => 'Int!'` in the response object to override type.
Audit
Dependencies
graphql-composerequiredPeer dependency required at version ^7.0.4 || ^8.0.0 || ^9.0.0
graphqlrequiredPeer dependency for GraphQL runtime; not listed in package.json but required in README