@akumzy/gri-prisma-select
Version:
Generate Prisma select object from GraphQL Resolve Info.
21 lines • 1.04 kB
JavaScript
import { mapSchema, getDirective, MapperKind } from "@graphql-tools/utils";
import { toPrismaSelect } from "./toPrismaSelect";
export function toPrismaSelectDirectiveTransformer(schema, directiveName) {
return mapSchema(schema, {
// Executes once for each object field definition in the schema
[MapperKind.OBJECT_FIELD]: (fieldConfig) => {
var _a;
const directive = (_a = getDirective(schema, fieldConfig, directiveName)) === null || _a === void 0 ? void 0 : _a[0];
if (directive) {
const { resolve } = fieldConfig;
fieldConfig.resolve = async function (source, arg, ctx, info) {
const prismaSelect = await toPrismaSelect(info);
ctx = { ...ctx, prismaSelect };
return resolve === null || resolve === void 0 ? void 0 : resolve.apply(this, [source, arg, ctx, info]);
};
}
return fieldConfig;
},
});
}
//# sourceMappingURL=directive.js.map