@graphql-eslint/eslint-plugin
Version:
GraphQL plugin for ESLint
56 lines (49 loc) • 1.89 kB
JavaScript
;Object.defineProperty(exports, "__esModule", {value: true});
var _graphql = require('graphql');
var _utilsjs = require('./utils.js');
function convertToESTree(node, schema) {
const typeInfo = schema && new (0, _graphql.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 === _graphql.Kind.DOCUMENT ? {
...node2,
definitions: node2.definitions.map(
(definition) => definition.rawNode()
)
} : node2, commonFields = {
...node2,
type: node2.kind,
loc: _utilsjs.convertLocation.call(void 0, 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 _graphql.visit.call(void 0,
node,
typeInfo ? _graphql.visitWithTypeInfo.call(void 0, typeInfo, visitor) : visitor
);
}
exports.convertToESTree = convertToESTree;