@graphql-mesh/runtime
Version:
46 lines (45 loc) • 1.44 kB
JavaScript
import { BREAK, getNamedType, visit } from 'graphql';
import { MapperKind, mapSchema, memoize1 } from '@graphql-tools/utils';
export const isStreamOperation = memoize1(function isStreamOperation(astNode) {
let isStream = false;
visit(astNode, {
Field: {
enter(node) {
if (node.directives?.some(d => d.name.value === 'stream')) {
isStream = true;
return BREAK;
}
return undefined;
},
},
});
return isStream;
});
export const isGraphQLJitCompatible = memoize1(function isGraphQLJitCompatible(schema) {
let compatibleSchema = true;
mapSchema(schema, {
[MapperKind.INPUT_OBJECT_TYPE]: type => {
const fieldMap = type.getFields();
for (const fieldName in fieldMap) {
const fieldObj = fieldMap[fieldName];
const namedType = getNamedType(fieldObj.type);
if (namedType.name === type.name) {
compatibleSchema = false;
return undefined;
}
}
return undefined;
},
});
if (compatibleSchema) {
try {
// eslint-disable-next-line no-new-func
const a = new Function('return true');
return a();
}
catch (e) {
return false;
}
}
return false;
});