polen
Version:
A framework for delightful GraphQL developer portals
25 lines • 878 B
JavaScript
import { Grafaid } from '#lib/grafaid/index';
export const locateTargetType = (schema, target) => {
const type = schema.getType(target.name);
if (!type) {
throw new Error(`Could not find type ${target.name}`);
}
return type;
};
export const locateTargetField = (schema, target) => {
const type = schema.getType(target.typeTarget.name);
if (!type) {
throw new Error(`Could not find type ${target.typeTarget.name}`);
}
if (!Grafaid.Schema.TypesLike.isFielded(type)) {
throw new Error(`Type ${target.typeTarget.name} does not have fields`);
}
const fields = type.getFields();
const field = fields[target.name];
if (!field) {
// dprint-ignore
throw new Error(`Could not find field ${target.name} on type ${target.typeTarget.name}`);
}
return field;
};
//# sourceMappingURL=target.js.map