UNPKG

@omnigraph/json-schema

Version:

This package generates GraphQL Schema from JSON Schema and sample JSON request and responses. You can define your root field endpoints like below in your GraphQL Config for example;

17 lines (16 loc) 617 B
import { sanitizeNameForGraphQL } from '@graphql-mesh/utils'; import { inspect } from '@graphql-tools/utils'; export function getValidTypeName({ schemaComposer, isInput, subSchema, }) { if (!subSchema.title) { throw new Error('Missing title for schema; ' + inspect(subSchema)); } const sanitizedName = sanitizeNameForGraphQL(isInput ? subSchema.title + '_Input' : subSchema.title); if (schemaComposer.has(sanitizedName)) { let i = 2; while (schemaComposer.has(sanitizedName + i)) { i++; } return sanitizedName + i; } return sanitizedName; }