Skip to content

Commit

Permalink
feat: documents query
Browse files Browse the repository at this point in the history
  • Loading branch information
froid1911 committed Apr 3, 2024
1 parent bed3b3d commit cd4b308
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/src/graphql/generated/drive/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,7 @@ export interface NexusGenFieldTypes {
coreUnit: NexusGenRootTypes['CoreUnit'] | null; // CoreUnit
coreUnits: Array<NexusGenRootTypes['CoreUnit'] | null> | null; // [CoreUnit]
document: NexusGenRootTypes['IDocument'] | null; // IDocument
documents: Array<NexusGenRootTypes['IDocument'] | null> | null; // [IDocument]
drive: NexusGenRootTypes['DocumentDriveState'] | null; // DocumentDriveState
rwaPortfolios: Array<NexusGenRootTypes['RealWorldAssetsPortfolio'] | null> | null; // [RealWorldAssetsPortfolio]
system: NexusGenRootTypes['SwitchboardDrive'] | null; // SwitchboardDrive
Expand Down Expand Up @@ -1347,6 +1348,7 @@ export interface NexusGenFieldTypeNames {
coreUnit: 'CoreUnit'
coreUnits: 'CoreUnit'
document: 'IDocument'
documents: 'IDocument'
drive: 'DocumentDriveState'
rwaPortfolios: 'RealWorldAssetsPortfolio'
system: 'SwitchboardDrive'
Expand Down
1 change: 1 addition & 0 deletions api/src/graphql/generated/drive/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ type Query {
coreUnit(id: String): CoreUnit
coreUnits: [CoreUnit]
document(id: String!): IDocument
documents: [IDocument]
drive: DocumentDriveState
rwaPortfolios: [RealWorldAssetsPortfolio]
system: SwitchboardDrive
Expand Down
5 changes: 5 additions & 0 deletions api/src/modules/document/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,5 +255,10 @@ export function getDocumentDriveCRUD(prisma: Prisma.TransactionClient) {
};
return response;
},

getDocuments: async (driveId: string) => {
const documents = await driveServer.getDocuments(driveId);
return documents;
}
}
}
16 changes: 15 additions & 1 deletion api/src/modules/document/resolvers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { interfaceType, nonNull, objectType, queryField } from 'nexus';
import { interfaceType, list, nonNull, objectType, queryField } from 'nexus';
import { GQLDateBase } from '../system';
import { Context } from '../../graphql/server/drive/context';

Expand Down Expand Up @@ -60,3 +60,17 @@ export const documentQuery = queryField('document', {
return doc;
},
});

export const documentsQuery = queryField('documents', {
type: list(documentModelInterface),
resolve: async (_root, { id }, ctx: Context) => {
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;
},
});

0 comments on commit cd4b308

Please sign in to comment.