@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;
47 lines (46 loc) • 2.5 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadGraphQLSchemaFromJSONSchemas = exports.loadNonExecutableGraphQLSchemaFromJSONSchemas = void 0;
const transport_rest_1 = require("@graphql-mesh/transport-rest");
const utils_1 = require("@graphql-mesh/utils");
const fetch_1 = require("@whatwg-node/fetch");
const getDereferencedJSONSchemaFromOperations_js_1 = require("./getDereferencedJSONSchemaFromOperations.js");
const getGraphQLSchemaFromDereferencedJSONSchema_js_1 = require("./getGraphQLSchemaFromDereferencedJSONSchema.js");
async function loadNonExecutableGraphQLSchemaFromJSONSchemas(name, options) {
options.logger = options.logger || new utils_1.DefaultLogger(name);
options.cwd = options.cwd || process.cwd();
const fullyDeferencedSchema = await (0, getDereferencedJSONSchemaFromOperations_js_1.getDereferencedJSONSchemaFromOperations)({
operations: options.operations,
operationHeaders: typeof options.operationHeaders === 'object' ? options.operationHeaders : {},
queryParams: options.queryParams,
endpoint: options.endpoint,
cwd: options.cwd,
logger: options.logger,
fetchFn: options.fetch,
schemaHeaders: options.schemaHeaders,
ignoreErrorResponses: options.ignoreErrorResponses,
});
return (0, getGraphQLSchemaFromDereferencedJSONSchema_js_1.getGraphQLSchemaFromDereferencedJSONSchema)(name, {
fullyDeferencedSchema,
logger: options.logger,
operations: options.operations,
operationHeaders: options.operationHeaders,
endpoint: options.endpoint,
queryParams: options.queryParams,
queryStringOptions: options.queryStringOptions,
getScalarForFormat: options.getScalarForFormat,
handlerName: options.handlerName,
});
}
exports.loadNonExecutableGraphQLSchemaFromJSONSchemas = loadNonExecutableGraphQLSchemaFromJSONSchemas;
async function loadGraphQLSchemaFromJSONSchemas(name, options) {
const graphqlSchema = await loadNonExecutableGraphQLSchemaFromJSONSchemas(name, options);
return (0, transport_rest_1.processDirectives)(graphqlSchema, {
...options,
operationHeaders: typeof options.operationHeaders === 'object' ? options.operationHeaders : {},
globalFetch: options.fetch || fetch_1.fetch,
pubsub: options.pubsub,
logger: options.logger,
});
}
exports.loadGraphQLSchemaFromJSONSchemas = loadGraphQLSchemaFromJSONSchemas;
;