UNPKG

@graphql-eslint/eslint-plugin

Version:
57 lines (56 loc) 1.79 kB
import "../chunk-U3TKCM4X.js"; import { Kind, TypeInfo, visit, visitWithTypeInfo } from "graphql"; import { convertLocation } from "./utils.js"; function convertToESTree(node, schema) { const typeInfo = schema && new TypeInfo(schema), visitor = { leave(node2, key, parent) { const leadingComments = "description" in node2 && node2.description ? [ { type: node2.description.block ? "Block" : "Line", value: node2.description.value } ] : [], calculatedTypeInfo = typeInfo ? { argument: typeInfo.getArgument(), defaultValue: typeInfo.getDefaultValue(), directive: typeInfo.getDirective(), enumValue: typeInfo.getEnumValue(), fieldDef: typeInfo.getFieldDef(), inputType: typeInfo.getInputType(), parentInputType: typeInfo.getParentInputType(), parentType: typeInfo.getParentType(), gqlType: typeInfo.getType() } : {}, rawNode = () => parent && key !== void 0 ? parent[key] : node2.kind === Kind.DOCUMENT ? { ...node2, definitions: node2.definitions.map( (definition) => definition.rawNode() ) } : node2, commonFields = { ...node2, type: node2.kind, loc: convertLocation(node2.loc), range: [node2.loc.start, node2.loc.end], leadingComments, // Use function to prevent RangeError: Maximum call stack size exceeded typeInfo: () => calculatedTypeInfo, // Don't know if can fix error rawNode }; return "type" in node2 ? { ...commonFields, gqlType: node2.type } : commonFields; } }; return visit( node, typeInfo ? visitWithTypeInfo(typeInfo, visitor) : visitor ); } export { convertToESTree };