From eaf4692d142a2e4fbb800d02628ea55833d95f84 Mon Sep 17 00:00:00 2001 From: Frank Date: Mon, 8 Jan 2024 10:52:43 +0100 Subject: [PATCH] feat: added operation mutations and drive queries --- api/src/generated/nexus.ts | 67 +------------- api/src/generated/schema.graphql | 25 ------ api/src/modules/DocumentDrive/definitions.ts | 87 +++++++------------ api/src/modules/DocumentDrive/mutations.ts | 15 ---- .../DocumentDrive/mutations/createDocument.ts | 13 --- .../modules/DocumentDrive/mutations/index.ts | 1 - .../modules/DocumentDrive/queries/document.ts | 17 ---- .../DocumentDrive/queries/documents.ts | 16 ---- .../modules/DocumentDrive/queries/drive.ts | 11 ++- .../modules/DocumentDrive/queries/index.ts | 4 +- 10 files changed, 46 insertions(+), 210 deletions(-) delete mode 100644 api/src/modules/DocumentDrive/mutations.ts delete mode 100644 api/src/modules/DocumentDrive/mutations/createDocument.ts delete mode 100644 api/src/modules/DocumentDrive/queries/document.ts delete mode 100644 api/src/modules/DocumentDrive/queries/documents.ts diff --git a/api/src/generated/nexus.ts b/api/src/generated/nexus.ts index 77103ecf..2e258dee 100644 --- a/api/src/generated/nexus.ts +++ b/api/src/generated/nexus.ts @@ -57,10 +57,6 @@ export interface NexusGenInputs { targetName?: string | null; // String targetParentFolder?: string | null; // ID } - CreateDocumentInput: { // input type - documentType: string; // String! - id: string; // ID! - } DeleteNodeInput: { // input type id: string; // ID! } @@ -137,12 +133,6 @@ export interface NexusGenObjects { count: number; // Int! message: string; // String! } - DocumentDriveState: { // root type - icon?: string | null; // String - id: string; // ID! - name: string; // String! - remoteUrl?: string | null; // String - } Mutation: {}; Query: {}; Session: { // root type @@ -167,13 +157,12 @@ export interface NexusGenObjects { } export interface NexusGenInterfaces { - Document: any; } export interface NexusGenUnions { } -export type NexusGenRootTypes = NexusGenInterfaces & NexusGenObjects +export type NexusGenRootTypes = NexusGenObjects export type NexusGenAllTypes = NexusGenRootTypes & NexusGenScalars @@ -197,19 +186,12 @@ export interface NexusGenFieldTypes { count: number; // Int! message: string; // String! } - DocumentDriveState: { // field return type - icon: string | null; // String - id: string; // ID! - name: string; // String! - remoteUrl: string | null; // String - } Mutation: { // field return type addDrive: boolean | null; // Boolean addFile: boolean | null; // Boolean addFolder: boolean | null; // Boolean copyNode: boolean | null; // Boolean createChallenge: NexusGenRootTypes['Challenge'] | null; // Challenge - createDocument: boolean | null; // Boolean createSession: NexusGenRootTypes['SessionOutput'] | null; // SessionOutput deleteDrive: boolean | null; // Boolean deleteNode: boolean | null; // Boolean @@ -226,9 +208,6 @@ export interface NexusGenFieldTypes { coreUnit: NexusGenRootTypes['CoreUnit'] | null; // CoreUnit coreUnits: Array | null; // [CoreUnit] countUsers: NexusGenRootTypes['Counter'] | null; // Counter - document: NexusGenRootTypes['Document'] | null; // Document - documents: Array | null; // [String] - drive: NexusGenRootTypes['DocumentDriveState'] | null; // DocumentDriveState drives: Array | null; // [String] me: NexusGenRootTypes['User'] | null; // User sessions: Array | null; // [Session] @@ -252,14 +231,6 @@ export interface NexusGenFieldTypes { address: string; // String! createdAt: NexusGenScalars['Date']; // Date! } - Document: { // field return type - created: string; // String! - documentType: string; // String! - id: string; // String! - lastModified: string; // String! - name: string; // String! - revision: string; // String! - } } export interface NexusGenFieldTypeNames { @@ -282,19 +253,12 @@ export interface NexusGenFieldTypeNames { count: 'Int' message: 'String' } - DocumentDriveState: { // field return type name - icon: 'String' - id: 'ID' - name: 'String' - remoteUrl: 'String' - } Mutation: { // field return type name addDrive: 'Boolean' addFile: 'Boolean' addFolder: 'Boolean' copyNode: 'Boolean' createChallenge: 'Challenge' - createDocument: 'Boolean' createSession: 'SessionOutput' deleteDrive: 'Boolean' deleteNode: 'Boolean' @@ -311,9 +275,6 @@ export interface NexusGenFieldTypeNames { coreUnit: 'CoreUnit' coreUnits: 'CoreUnit' countUsers: 'Counter' - document: 'Document' - documents: 'String' - drive: 'DocumentDriveState' drives: 'String' me: 'User' sessions: 'Session' @@ -337,14 +298,6 @@ export interface NexusGenFieldTypeNames { address: 'String' createdAt: 'Date' } - Document: { // field return type name - created: 'String' - documentType: 'String' - id: 'String' - lastModified: 'String' - name: 'String' - revision: 'String' - } } export interface NexusGenArgTypes { @@ -368,10 +321,6 @@ export interface NexusGenArgTypes { createChallenge: { // args address: string; // String! } - createDocument: { // args - driveId: string; // String! - input: NexusGenInputs['CreateDocumentInput']; // CreateDocumentInput! - } createSession: { // args session: NexusGenInputs['SessionInput']; // SessionInput! } @@ -421,16 +370,6 @@ export interface NexusGenArgTypes { countUsers: { // args message: string; // String! } - document: { // args - drive: string; // String! - id: string; // String! - } - documents: { // args - drive: string; // String! - } - drive: { // args - id: string; // String! - } } } @@ -446,7 +385,7 @@ export type NexusGenInputNames = keyof NexusGenInputs; export type NexusGenEnumNames = never; -export type NexusGenInterfaceNames = keyof NexusGenInterfaces; +export type NexusGenInterfaceNames = never; export type NexusGenScalarNames = keyof NexusGenScalars; @@ -454,7 +393,7 @@ export type NexusGenUnionNames = never; export type NexusGenObjectsUsingAbstractStrategyIsTypeOf = never; -export type NexusGenAbstractsUsingStrategyResolveType = "Document"; +export type NexusGenAbstractsUsingStrategyResolveType = never; export type NexusGenFeaturesConfig = { abstractTypeStrategies: { diff --git a/api/src/generated/schema.graphql b/api/src/generated/schema.graphql index 858a3e23..cbc00531 100644 --- a/api/src/generated/schema.graphql +++ b/api/src/generated/schema.graphql @@ -44,11 +44,6 @@ type Counter { message: String! } -input CreateDocumentInput { - documentType: String! - id: ID! -} - """Date custom scalar type""" scalar Date @@ -56,27 +51,11 @@ input DeleteNodeInput { id: ID! } -interface Document { - created: String! - documentType: String! - id: String! - lastModified: String! - name: String! - revision: String! -} - input DocumentDriveLocalStateInput { availableOffline: Boolean! sharingType: String } -type DocumentDriveState { - icon: String - id: ID! - name: String! - remoteUrl: String -} - input DocumentDriveStateInput { icon: String id: ID! @@ -95,7 +74,6 @@ type Mutation { addFolder(drive: String!, operation: AddFolderInput!): Boolean copyNode(drive: String!, operation: CopyNodeInput!): Boolean createChallenge(address: String!): Challenge - createDocument(driveId: String!, input: CreateDocumentInput!): Boolean createSession(session: SessionInput!): SessionOutput deleteDrive(id: String!): Boolean deleteNode(drive: String!, operation: DeleteNodeInput!): Boolean @@ -113,9 +91,6 @@ type Query { coreUnit(id: String): CoreUnit coreUnits: [CoreUnit] countUsers(message: String!): Counter - document(drive: String!, id: String!): Document - documents(drive: String!): [String] - drive(id: String!): DocumentDriveState drives: [String] me: User sessions: [Session] diff --git a/api/src/modules/DocumentDrive/definitions.ts b/api/src/modules/DocumentDrive/definitions.ts index 00943d65..a05e8b61 100644 --- a/api/src/modules/DocumentDrive/definitions.ts +++ b/api/src/modules/DocumentDrive/definitions.ts @@ -7,16 +7,6 @@ export const DocumentDriveLocalState = objectType({ t.nonNull.boolean('availableOffline'); }, }); -export const DocumentDriveState = objectType({ - name: 'DocumentDriveState', - definition(t) { - t.nonNull.id('id'); - t.nonNull.string('name'); - // t.nonNull.list.nonNull.field('nodes', { type: UnionNode }); - t.string('icon'); - t.string('remoteUrl'); - }, -}); export const DocumentDriveLocalStateInput = inputObjectType({ name: 'DocumentDriveLocalStateInput', @@ -35,26 +25,6 @@ export const DocumentDriveStateInput = inputObjectType({ }, }); -export const FileNode = objectType({ - name: 'FileNode', - definition(t) { - t.nonNull.string('id'); - t.nonNull.string('name'); - t.nonNull.string('kind'); - t.nonNull.string('documentType'); - t.string('parentFolder'); - }, -}); -export const FolderNode = objectType({ - name: 'FolderNode', - definition(t) { - t.nonNull.string('id'); - t.nonNull.string('name'); - t.nonNull.string('kind'); - t.string('parentFolder'); - }, -}); - export const AddFileInput = inputObjectType({ name: 'AddFileInput', definition(t) { @@ -139,40 +109,47 @@ export const UpdateNodeInput = inputObjectType({ }, }); -export const UnionNode = unionType({ - name: 'Node', - resolveType(node) { - return node.kind === 'file' ? 'FileNode' : 'FolderNode'; - }, +export const FileNode = objectType({ + name: 'FileNode', definition(t) { - t.members(FolderNode, FileNode); + t.nonNull.string('id'); + t.nonNull.string('name'); + t.nonNull.string('kind'); + t.nonNull.string('documentType'); + t.string('parentFolder'); }, }); - -export const CreateDocumentInput = inputObjectType({ - name: 'CreateDocumentInput', +export const FolderNode = objectType({ + name: 'FolderNode', definition(t) { - t.nonNull.id('id'); - t.nonNull.string('documentType'); + t.nonNull.string('id'); + t.nonNull.string('name'); + t.nonNull.string('kind'); + t.string('parentFolder'); }, }); -export const Document = interfaceType({ - name: 'Document', - resolveType: (document) => { - switch (document.documentType) { - case 'document-drive': - return 'DocumentDriveDocument'; - default: - return null; +export const Node = unionType({ + name: 'Node', + resolveType(node) { + if (node.kind === 'folder') { + return FolderNode; } + + return FileNode; }, definition(t) { - t.nonNull.string('id', { resolve: (doc) => doc.id }); - t.nonNull.string('name', { resolve: (doc) => doc.name }); - t.nonNull.string('documentType', { resolve: (doc) => doc.documentType }); - t.nonNull.string('lastModified', { resolve: (doc) => doc.lastModified }); - t.nonNull.string('revision', { resolve: (doc) => doc.revision }); - t.nonNull.string('created', { resolve: (doc) => doc.created }); + t.members(FileNode, FolderNode); + }, +}); + +export const DocumentDriveState = objectType({ + name: 'DocumentDriveState', + definition(t) { + t.nonNull.id('id'); + t.nonNull.string('name'); + t.nonNull.list.field('nodes', { type: Node }); + t.string('icon'); + t.string('remoteUrl'); }, }); diff --git a/api/src/modules/DocumentDrive/mutations.ts b/api/src/modules/DocumentDrive/mutations.ts deleted file mode 100644 index aacd22e9..00000000 --- a/api/src/modules/DocumentDrive/mutations.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { mutationField, nonNull } from 'nexus'; -import { - AddFileInput, - AddFolderInput, - CopyNodeInput, - DeleteNodeInput, - DocumentDriveLocalStateInput, - DocumentDriveStateInput, - MoveNodeInput, -} from './definitions'; -import { SetSharingTypeInputSchema } from 'document-model-libs/dist/document-models/document-drive/gen/schema/zod'; - - - - diff --git a/api/src/modules/DocumentDrive/mutations/createDocument.ts b/api/src/modules/DocumentDrive/mutations/createDocument.ts deleted file mode 100644 index 1bfe20df..00000000 --- a/api/src/modules/DocumentDrive/mutations/createDocument.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { mutationField, nonNull } from "nexus"; -import { CreateDocumentInput } from "../definitions"; - -export const createDocument = mutationField('createDocument', { - type: 'Boolean', - args: { - driveId: nonNull('String'), - input: nonNull(CreateDocumentInput), - }, - resolve: (_parent, { driveId, input }, ctx) => { - return ctx.prisma.drive.createDocument(driveId, input); - }, -}); diff --git a/api/src/modules/DocumentDrive/mutations/index.ts b/api/src/modules/DocumentDrive/mutations/index.ts index 6e2917f4..d5c2fa42 100644 --- a/api/src/modules/DocumentDrive/mutations/index.ts +++ b/api/src/modules/DocumentDrive/mutations/index.ts @@ -2,7 +2,6 @@ export * from './addFile'; export * from './addFolder'; export * from './addDrive'; export * from './copyNode'; -export * from './createDocument'; export * from './deleteDrive'; export * from './deleteNode'; export * from './moveNode'; diff --git a/api/src/modules/DocumentDrive/queries/document.ts b/api/src/modules/DocumentDrive/queries/document.ts deleted file mode 100644 index d64d2009..00000000 --- a/api/src/modules/DocumentDrive/queries/document.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { nonNull, queryField } from 'nexus'; -import { Document } from '../definitions'; - -export const getDocument = queryField('document', { - type: Document, - args: { - drive: nonNull('String'), - id: nonNull('String'), - }, - resolve: async (_parent, { drive, id }, ctx) => { - try { - return await ctx.prisma.drive.getDocument(drive, id); - } catch (e) { - return null; - } - }, -}); diff --git a/api/src/modules/DocumentDrive/queries/documents.ts b/api/src/modules/DocumentDrive/queries/documents.ts deleted file mode 100644 index a5da2086..00000000 --- a/api/src/modules/DocumentDrive/queries/documents.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { list, nonNull, queryField } from 'nexus'; -import { Document } from '../definitions'; - -export const getDocuments = queryField('documents', { - type: list('String'), - args: { - drive: nonNull('String'), - }, - resolve: async (_parent, { drive }, ctx) => { - try { - return await ctx.prisma.drive.getDocuments(drive); - } catch (e) { - return []; - } - }, -}); diff --git a/api/src/modules/DocumentDrive/queries/drive.ts b/api/src/modules/DocumentDrive/queries/drive.ts index b1a3cc8e..c7f1a254 100644 --- a/api/src/modules/DocumentDrive/queries/drive.ts +++ b/api/src/modules/DocumentDrive/queries/drive.ts @@ -8,7 +8,16 @@ export const getDrive = queryField('drive', { }, resolve: async (_parent, { id }, ctx) => { try { - return await ctx.prisma.drive.getDrive(id); + const drive = await ctx.prisma.drive.getDrive(id); + const response = { + id: drive.id, + name: drive.name, + icon: drive.icon, + remoteUrl: drive.remoteUrl, + nodes: drive.nodes + }; + + return drive; } catch (e) { return null; } diff --git a/api/src/modules/DocumentDrive/queries/index.ts b/api/src/modules/DocumentDrive/queries/index.ts index 81aaf0f6..eff1340d 100644 --- a/api/src/modules/DocumentDrive/queries/index.ts +++ b/api/src/modules/DocumentDrive/queries/index.ts @@ -1,4 +1,2 @@ -export * from './document'; -export * from './documents'; -export * from './drive'; +// export * from './drive'; export * from './drives';