@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;
63 lines (62 loc) • 2.59 kB
TypeScript
import { MeshPubSub, Logger } from '@graphql-mesh/types';
import { BaseLoaderOptions } from '@graphql-tools/utils';
import { GraphQLInputType, OperationTypeNode } from 'graphql';
import { JSONSchema, JSONSchemaObject } from 'json-machete';
import { IStringifyOptions } from 'qs';
export interface JSONSchemaLoaderOptions extends BaseLoaderOptions {
baseUrl?: string;
operationHeaders?: Record<string, string>;
schemaHeaders?: Record<string, string>;
operations: JSONSchemaOperationConfig[];
errorMessage?: string;
logger?: Logger;
pubsub?: MeshPubSub;
fetch?: WindowOrWorkerGlobalScope['fetch'];
ignoreErrorResponses?: boolean;
queryParams?: Record<string, string>;
noDeduplication?: boolean;
queryStringOptions?: IStringifyOptions;
}
export interface JSONSchemaOperationResponseConfig {
responseSchema?: string | JSONSchemaObject;
responseSample?: any;
responseTypeName?: string;
exposeResponseMetadata?: boolean;
links?: Record<string, JSONSchemaLinkConfig>;
}
export interface JSONSchemaLinkConfig {
fieldName: string;
args?: Record<string, string>;
description?: string;
}
export declare type JSONSchemaBaseOperationConfig = {
type: OperationTypeNode;
field: string;
description?: string;
argTypeMap?: Record<string, string | GraphQLInputType>;
} & ({
responseByStatusCode?: Record<string, JSONSchemaOperationResponseConfig>;
} | JSONSchemaOperationResponseConfig);
export declare type JSONSchemaBaseOperationConfigWithJSONRequest = JSONSchemaBaseOperationConfig & {
requestSchema?: string | JSONSchema;
requestSample?: any;
requestTypeName?: string;
requestBaseBody?: any;
};
export declare type HTTPMethod = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'DELETE' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH';
export declare type JSONSchemaHTTPBaseOperationConfig = JSONSchemaBaseOperationConfig & {
path: string;
method?: HTTPMethod;
headers?: Record<string, string>;
};
export declare type JSONSchemaHTTPJSONOperationConfig = JSONSchemaHTTPBaseOperationConfig & JSONSchemaBaseOperationConfigWithJSONRequest;
export declare type JSONSchemaPubSubOperationConfig = JSONSchemaBaseOperationConfigWithJSONRequest & {
pubsubTopic: string;
};
export declare type JSONSchemaHTTPBinaryConfig = JSONSchemaHTTPBaseOperationConfig & {
path: string;
method?: HTTPMethod;
requestTypeName?: string;
binary: true;
};
export declare type JSONSchemaOperationConfig = JSONSchemaHTTPJSONOperationConfig | JSONSchemaHTTPBinaryConfig | JSONSchemaPubSubOperationConfig;