@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;
55 lines (54 loc) • 1.56 kB
JavaScript
export function isPubSubOperationConfig(operationConfig) {
return 'pubsubTopic' in operationConfig;
}
export 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,
};
}
export 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;
}
export function isFile(obj) {
return typeof obj.arrayBuffer === 'function';
}