Registry / devops / core-types-graphql

core-types-graphql

JSON →
library3.0.0jsnpmunverified

Conversion library between core-types and GraphQL (code/AST). Current stable version 3.0.0, pure ESM, requires Node >=14.13.1 || >=16.0.0. Part of the typeconv ecosystem alongside core-types-ts and core-types-json-schema. Typically used indirectly via typeconv. Provides bidirectional conversion, custom name generation for inline types, and warning/error handling for unsupported GraphQL features.

npm install core-types-graphql
INSTALL
IMPORT
SIG · CORE-TYPES-GRAPHQL
C
core-types-graphql
devopsjavascriptv3.0.0
harness data pending
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.

convertCoreTypesToGraphql
import { convertCoreTypesToGraphql } from 'core-types-graphql'
const convertCoreTypesToGraphql = require('core-types-graphql').convertCoreTypesToGraphql
ESM-only since v3. CommonJS require throws ERR_REQUIRE_ESM.
convertGraphqlToCoreTypes
import { convertGraphqlToCoreTypes } from 'core-types-graphql'
import convertGraphqlToCoreTypes from 'core-types-graphql'
Named export, not default.
convertCoreTypesToGraphqlAst
import { convertCoreTypesToGraphqlAst } from 'core-types-graphql'
Converts to GraphQL AST instead of string. Same options as convertCoreTypesToGraphql.

Converts a core-types document with object and union types to GraphQL schema string, showing auto-generated name for inline types.

import { convertCoreTypesToGraphql } from 'core-types-graphql'; // Example core-types document const doc = { version: 2, types: [ { type: 'object', name: 'User', properties: { id: { type: 'string' }, name: { type: 'string' }, email: { type: 'string' }, }, }, { type: 'union', name: 'Result', members: [ { type: 'object', name: 'Success', properties: { data: { type: 'string' } } }, { type: 'object', name: 'Error', properties: { message: { type: 'string' } } }, ], }, ], }; const { data: graphQL } = convertCoreTypesToGraphql(doc, { filename: 'schema.graphql', unsupported: 'warn', }); console.log(graphQL); // Output: // # Auto-generated file - do not edit // // type User { // id: String! // name: String! // email: String! // } // // type Success { // data: String! // } // // type Error { // message: String! // } // // union Result = Success | Error
Debug
Known issues
breakingVersion 3.0 is pure ESM. CommonJS require() will throw ERR_REQUIRE_ESM.
fix
Use dynamic import() or switch your project to ESM (e.g., type:module in package.json).
affects: >=3.0
gotchaInline object/union types are not supported in GraphQL and require name generation. If nameGenerator is not provided, a default generator is used which may produce non-semantic names.
fix
Provide a custom nameGenerator function that produces meaningful names based on context.
affects: >=1.0
gotchaThe 'unsupported' option defaults to 'warn', so unsupported types are silently skipped with a warning. This may lead to incomplete schema without error.
fix
Set unsupported to 'error' during development to catch unsupported types early.
affects: >=1.0
gotchaGraphQL type names must be unique and follow naming conventions (uppercase start). core-types names violating this will pass through but produce invalid GraphQL.
fix
Validate your core-types names against GraphQL naming rules before conversion.
affects: >=1.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/node_modules/core-types-graphql/dist/index.js
Using CommonJS require() with an ESM-only package (v3+).
fix
Change to dynamic import: const { convertCoreTypesToGraphql } = await import('core-types-graphql'); or use ESM throughout.
TypeError: convertCoreTypesToGraphql is not a function
Importing default export instead of named export.
fix
Use import { convertCoreTypesToGraphql } from 'core-types-graphql' (curly braces).
GraphQLError: Syntax Error: Expected Name, found String "..."
core-types property names with special characters like '@' that are not valid GraphQL identifiers.
fix
Sanitize property names before conversion or use a nameGenerator that replaces invalid characters.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
core-typesrequiredProvides core-types types and conversion result wrapper
Agent activity
4 hits · last 30 days
node
4
Resources
core-types-graphql — npm install core-types-graphql · libregistry