Skip to content

Commit

Permalink
feat: added query to fetch all documents at once from a drive
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Apr 3, 2024
1 parent cd4b308 commit 93e35bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
25 changes: 18 additions & 7 deletions api/src/modules/document/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { interfaceType, list, nonNull, objectType, queryField } from 'nexus';
import { GQLDateBase } from '../system';
import { Context } from '../../graphql/server/drive/context';
import { getChildLogger } from '../../logger';

const logger = getChildLogger({ msgPrefix: 'DOCUMENT RESOLVER' });

// todo: resolveType should be moved to somewhere else
export const operationModelInterface = interfaceType({
Expand Down Expand Up @@ -56,8 +59,12 @@ export const documentQuery = queryField('document', {
if (!ctx.driveId) {
throw new Error("DriveId is not defined")
}
const doc = await ctx.prisma.document.getDocument(ctx.driveId, id);
return doc;
try {
const doc = await ctx.prisma.document.getDocument(ctx.driveId, id);
return doc;
} catch (e: any) {
logger.error({ msg: e.message });
}
},
});

Expand All @@ -67,10 +74,14 @@ export const documentsQuery = queryField('documents', {
if (!ctx.driveId) {
throw new Error("DriveId is not defined")
}
const docIds = await ctx.prisma.document.getDocuments(ctx.driveId);
const docs = await Promise.all(docIds.map(doc => {
return ctx.prisma.document.getDocument(ctx.driveId!, doc);
}));
return docs;
try {
const docIds = await ctx.prisma.document.getDocuments(ctx.driveId);
const docs = await Promise.all(docIds.map(doc => {
return ctx.prisma.document.getDocument(ctx.driveId!, doc);
}));
return docs;
} catch (e: any) {
logger.error({ msg: e.message });
}
},
});
11 changes: 9 additions & 2 deletions api/src/modules/real-world-assets/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { enumType, interfaceType, list, objectType, queryField, unionType } from 'nexus';
import { GQLDateBase } from '../system';
import { documentModelInterface } from '../document';
import { getChildLogger } from '../../logger';

const logger = getChildLogger({ msgPrefix: 'REAL WORLD ASSETS RESOLVER' });

export const Account = objectType({
name: "Account",
Expand Down Expand Up @@ -165,8 +168,12 @@ export const rwaQuery = queryField('rwaPortfolios', {
// ),
// },
resolve: async (_root, args, ctx) => {
const doc = await ctx.prisma.rWAPortfolio.findRWAPortfolios({ driveId: ctx.driveId });
return doc;
try {
const doc = await ctx.prisma.rWAPortfolio.findRWAPortfolios({ driveId: ctx.driveId });
return doc;
} catch (e: any) {
logger.error({ msg: e.message });
}
},
});

0 comments on commit 93e35bf

Please sign in to comment.