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;

62 lines (61 loc) 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isFile = exports.cleanObject = exports.getOperationMetadata = exports.isPubSubOperationConfig = void 0; function isPubSubOperationConfig(operationConfig) { return 'pubsubTopic' in operationConfig; } exports.isPubSubOperationConfig = isPubSubOperationConfig; function getOperationMetadata(operationConfig) { let httpMethod; let operationType; let rootTypeName; if (isPubSubOperationConfig(operationConfig)) { httpMethod = null; operationType = 'subscription'; rootTypeName = 'Subscription'; } else { httpMethod = operationConfig.method; // Fix compability with Mesh handler operationType = operationConfig.type.toLowerCase(); if (!httpMethod) { if (operationType === 'mutation') { httpMethod = 'POST'; } else { httpMethod = 'GET'; } } if (!rootTypeName) { if (httpMethod === 'GET') { rootTypeName = 'Query'; } } rootTypeName = operationType === 'query' ? 'Query' : 'Mutation'; } return { httpMethod, operationType, rootTypeName, fieldName: operationConfig.field, }; } exports.getOperationMetadata = getOperationMetadata; function cleanObject(obj) { if (typeof obj === 'object' && obj != null) { const newObj = Array.isArray(obj) ? [] : {}; for (const key in obj) { const newObjForKey = cleanObject(obj[key]); if (newObjForKey != null) { newObj[key] = newObjForKey; } } return newObj; } return obj; } exports.cleanObject = cleanObject; function isFile(obj) { return typeof obj.arrayBuffer === 'function'; } exports.isFile = isFile;