API Reference
convertJsonSchemaToGraphQL(schema, options?)
Converts a JSON Schema object (or JSON string) to GraphQL SDL.
import { convertJsonSchemaToGraphQL } from "@json-schema-x-graphql/core";
const sdl = convertJsonSchemaToGraphQL(schema, options);Parameters
| Parameter | Type | Description |
|---|---|---|
schema | object | string | JSON Schema (parsed or JSON string) |
options | ConvertOptions | Optional conversion options (see below) |
ConvertOptions
| Option | Type | Default | Description |
|---|---|---|---|
federation | FederationOptions | false | false | Federation v2 generation options |
useInputTypes | boolean | false | Emit input types for mutation arguments |
scalarMap | Record<string, string> | {} | Override default JSON Schema format → GraphQL scalar mappings |
addTypename | boolean | false | Add __typename: String! to every type |
enumStrategy | 'all' | 'common' | 'all' | How to handle enum values |
convertGraphQLToJsonSchema(sdl, options?)
Converts a GraphQL SDL string back to a JSON Schema object.
import { convertGraphQLToJsonSchema } from "@json-schema-x-graphql/core";
const schema = convertGraphQLToJsonSchema(sdl, options);Parameters
| Parameter | Type | Description |
|---|---|---|
sdl | string | GraphQL SDL string |
options | ReverseConvertOptions | Optional options |
validateJsonSchema(schema)
Validates a JSON Schema against the Draft-07 meta-schema. Returns { valid, errors }.
validateGraphQL(sdl)
Validates GraphQL SDL against the GraphQL spec. Returns { valid, errors }.
TypeScript types
All types are exported from the package root:
import type {
ConvertOptions,
ReverseConvertOptions,
FederationOptions,
ConversionResult,
ValidationResult,
} from "@json-schema-x-graphql/core";