@graphql-hive/core
Version:
32 lines (31 loc) • 1.37 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.pathToCoordinate = pathToCoordinate;
const graphql_1 = require("graphql");
function pathToCoordinate(schema, errorPath, operationType = 'query') {
let currentType;
if (operationType === 'mutation')
currentType = schema.getMutationType();
else if (operationType === 'subscription')
currentType = schema.getSubscriptionType();
else
currentType = schema.getQueryType();
let coordinate = null;
for (const segment of errorPath) {
// Skip array indices entirely (they don't change the underlying type)
if (typeof segment === 'number')
continue;
currentType = (0, graphql_1.getNamedType)(currentType);
if ((0, graphql_1.isObjectType)(currentType) || (0, graphql_1.isInterfaceType)(currentType)) {
const fields = currentType.getFields();
const field = fields[segment];
if (!field) {
console.warn(`Hive Usage Client: Field '${segment}' not found on type '${currentType.name}'. Was this aliased? Error ignored.`);
return;
}
coordinate = `${currentType.name}.${field.name}`;
currentType = field.type;
}
}
return coordinate !== null && coordinate !== void 0 ? coordinate : undefined;
}