UNPKG

@graphql-eslint/eslint-plugin

Version:
84 lines (83 loc) 2.96 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var converter_exports = {}; __export(converter_exports, { convertToESTree: () => convertToESTree }); module.exports = __toCommonJS(converter_exports); var import_graphql = require("graphql"); var import_utils = require("./utils.js"); function convertToESTree(node, schema) { const typeInfo = schema && new import_graphql.TypeInfo(schema); const visitor = { leave(node2, key, parent) { const leadingComments = "description" in node2 && node2.description ? [ { type: node2.description.block ? "Block" : "Line", value: node2.description.value } ] : []; const 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() } : {}; const rawNode = () => { if (parent && key !== void 0) { return parent[key]; } return node2.kind === import_graphql.Kind.DOCUMENT ? { ...node2, definitions: node2.definitions.map( (definition) => definition.rawNode() ) } : node2; }; const commonFields = { ...node2, type: node2.kind, loc: (0, import_utils.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 (0, import_graphql.visit)( node, typeInfo ? (0, import_graphql.visitWithTypeInfo)(typeInfo, visitor) : visitor ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { convertToESTree });