Skip to content

Commit

Permalink
pothos-native select in ModelExport
Browse files Browse the repository at this point in the history
  • Loading branch information
berekuk committed Apr 9, 2024
1 parent f6777c9 commit 5d09d47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 22 deletions.
3 changes: 0 additions & 3 deletions packages/hub/src/graphql/queries/exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ builder.queryField("modelExports", (t) =>
createdAt: "desc",
},
},
include: {
modelRevision: true,
},
});
},
},
Expand Down
29 changes: 10 additions & 19 deletions packages/hub/src/graphql/types/ModelExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,30 @@ export const ModelExport = builder.prismaNode("ModelExport", {
title: t.exposeString("title", { nullable: true }),
owner: t.field({
type: Owner,
resolve: async (modelExport, _, context) => {
//There might be a way to do this using "select" or "resolve", but I couldn't get those to work.
const modelRevision = await prisma.modelRevision.findUnique({
where: { id: modelExport.modelRevisionId },
include: {
select: {
modelRevision: {
select: {
model: {
include: {
select: {
owner: {
include: {
select: {
user: true,
group: true,
},
},
},
},
},
});

if (!modelRevision || !modelRevision.model) {
throw new Error("Invalid model revision or model");
}

const owner = modelRevision.model.owner;
const result = owner.user ?? owner.group;

},
},
resolve: async ({ modelRevision: { model } }) => {
const result = model.owner.user ?? model.owner.group;
if (!result) {
throw new Error("Invalid owner object, missing user or group");
}

(result as any)["_owner"] = {
type: owner.user ? "User" : "Group",
type: model.owner.user ? "User" : "Group",
};

return result;
},
}),
Expand Down

0 comments on commit 5d09d47

Please sign in to comment.