@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;
40 lines (39 loc) • 1.94 kB
TypeScript
import { JSONSchemaObject } from 'json-machete';
import { Logger, MeshFetch, MeshPubSub } from '@graphql-mesh/types';
import { JSONSchemaOperationConfig, OperationHeadersConfiguration } from './types';
import { GraphQLSchema } from 'graphql';
import type { IStringifyOptions } from 'qs';
export interface JSONSchemaLoaderBundle {
name?: string;
baseUrl?: string;
operations: JSONSchemaOperationConfig[];
operationHeaders?: Record<string, string>;
referencedSchema: JSONSchemaObject;
}
export interface JSONSchemaLoaderBundleOptions {
baseUrl?: string;
operations: JSONSchemaOperationConfig[];
schemaHeaders?: Record<string, string>;
operationHeaders?: Record<string, string>;
queryParams?: Record<string, string | number | boolean>;
cwd: string;
ignoreErrorResponses?: boolean;
fetch?: WindowOrWorkerGlobalScope['fetch'];
logger?: Logger;
}
export declare function createBundle(name: string, { baseUrl, operations, schemaHeaders, operationHeaders, queryParams, cwd, fetch, logger, ignoreErrorResponses, }: JSONSchemaLoaderBundleOptions): Promise<JSONSchemaLoaderBundle>;
export interface JSONSchemaLoaderBundleToGraphQLSchemaOptions {
cwd?: string;
fetch?: MeshFetch;
pubsub?: MeshPubSub;
logger?: Logger;
baseUrl?: string;
operationHeaders?: OperationHeadersConfiguration;
queryParams?: Record<string, string>;
queryStringOptions?: IStringifyOptions;
}
/**
* Generates a local GraphQLSchema instance from
* previously generated JSON Schema bundle
*/
export declare function getGraphQLSchemaFromBundle({ name, baseUrl: bundledBaseUrl, operations, operationHeaders: bundledOperationHeaders, referencedSchema, }: JSONSchemaLoaderBundle, { cwd, fetch, pubsub, logger, baseUrl: overwrittenBaseUrl, operationHeaders: additionalOperationHeaders, queryParams, queryStringOptions, }?: JSONSchemaLoaderBundleToGraphQLSchemaOptions): Promise<GraphQLSchema>;