UNPKG

@graphql-mesh/runtime

Version:
49 lines (48 loc) 1.63 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isGraphQLJitCompatible = exports.isStreamOperation = void 0; const graphql_1 = require("graphql"); const utils_1 = require("@graphql-tools/utils"); exports.isStreamOperation = (0, utils_1.memoize1)(function isStreamOperation(astNode) { let isStream = false; (0, graphql_1.visit)(astNode, { Field: { enter(node) { if (node.directives?.some(d => d.name.value === 'stream')) { isStream = true; return graphql_1.BREAK; } return undefined; }, }, }); return isStream; }); exports.isGraphQLJitCompatible = (0, utils_1.memoize1)(function isGraphQLJitCompatible(schema) { let compatibleSchema = true; (0, utils_1.mapSchema)(schema, { [utils_1.MapperKind.INPUT_OBJECT_TYPE]: type => { const fieldMap = type.getFields(); for (const fieldName in fieldMap) { const fieldObj = fieldMap[fieldName]; const namedType = (0, graphql_1.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; });