From da9729b7aa7a880c073d7502d8980db609bf61f2 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 3 Apr 2024 18:40:37 +0200 Subject: [PATCH] fix: document operations type --- api/src/graphql/generated/drive/nexus.ts | 82 ++++++++++++------- .../graphql/generated/drive/schema.graphql | 33 +++++--- api/src/modules/document/resolvers.ts | 15 +++- 3 files changed, 83 insertions(+), 47 deletions(-) diff --git a/api/src/graphql/generated/drive/nexus.ts b/api/src/graphql/generated/drive/nexus.ts index 9906cadd..2d2bbda2 100644 --- a/api/src/graphql/generated/drive/nexus.ts +++ b/api/src/graphql/generated/drive/nexus.ts @@ -134,7 +134,7 @@ export interface NexusGenObjects { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['AccountSnapshotState']; // AccountSnapshotState! } @@ -195,7 +195,7 @@ export interface NexusGenObjects { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['BudgetStatementState']; // BudgetStatementState! } @@ -257,9 +257,15 @@ export interface NexusGenObjects { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! } + DefaultOperation: { // root type + hash: string; // String! + index: number; // Int! + timestamp: NexusGenScalars['Date']; // Date! + type: string; // String! + } DocumentDriveState: { // root type icon?: string | null; // String id: string; // ID! @@ -393,7 +399,7 @@ export interface NexusGenObjects { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['RealWorldAssetsState']; // RealWorldAssetsState! } @@ -432,7 +438,7 @@ export interface NexusGenObjects { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['ScopeFrameworkState']; // ScopeFrameworkState! } @@ -562,8 +568,8 @@ export interface NexusGenObjects { export interface NexusGenInterfaces { IDocument: NexusGenRootTypes['AccountSnapshot'] | NexusGenRootTypes['BudgetStatement'] | NexusGenRootTypes['DefaultDocument'] | NexusGenRootTypes['RealWorldAssets'] | NexusGenRootTypes['ScopeFramework']; + IOperation: NexusGenRootTypes['DefaultOperation']; IRealWorldAssetsState: NexusGenRootTypes['RealWorldAssetsPortfolio'] | NexusGenRootTypes['RealWorldAssetsState']; - Operation: any; System: NexusGenRootTypes['SwitchboardDrive'] | NexusGenRootTypes['SwitchboardHost']; } @@ -588,7 +594,7 @@ export interface NexusGenFieldTypes { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['AccountSnapshotState']; // AccountSnapshotState! } @@ -652,7 +658,7 @@ export interface NexusGenFieldTypes { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['BudgetStatementState']; // BudgetStatementState! } @@ -714,9 +720,15 @@ export interface NexusGenFieldTypes { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! } + DefaultOperation: { // field return type + hash: string; // String! + index: number; // Int! + timestamp: NexusGenScalars['Date']; // Date! + type: string; // String! + } DocumentDriveState: { // field return type icon: string | null; // String id: string; // ID! @@ -867,7 +879,7 @@ export interface NexusGenFieldTypes { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['RealWorldAssetsState']; // RealWorldAssetsState! } @@ -906,7 +918,7 @@ export interface NexusGenFieldTypes { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! state: NexusGenRootTypes['ScopeFrameworkState']; // ScopeFrameworkState! } @@ -1045,9 +1057,15 @@ export interface NexusGenFieldTypes { id: string; // String! lastModified: NexusGenScalars['Date']; // Date! name: string; // String! - operations: NexusGenRootTypes['Operation'][]; // [Operation!]! + operations: NexusGenRootTypes['DefaultOperation'][]; // [DefaultOperation!]! revision: number; // Int! } + IOperation: { // field return type + hash: string; // String! + index: number; // Int! + timestamp: NexusGenScalars['Date']; // Date! + type: string; // String! + } IRealWorldAssetsState: { // field return type accounts: NexusGenRootTypes['Account'][]; // [Account!]! fixedIncomeTypes: NexusGenRootTypes['FixedIncomeType'][]; // [FixedIncomeType!]! @@ -1057,12 +1075,6 @@ export interface NexusGenFieldTypes { spvs: NexusGenRootTypes['Spv'][]; // [Spv!]! transactions: NexusGenRootTypes['GroupTransaction'][]; // [GroupTransaction!]! } - Operation: { // field return type - hash: string; // String! - index: number; // Int! - timestamp: NexusGenScalars['Date']; // Date! - type: string; // String! - } System: { // field return type auth: NexusGenRootTypes['Auth'] | null; // Auth } @@ -1080,7 +1092,7 @@ export interface NexusGenFieldTypeNames { id: 'String' lastModified: 'Date' name: 'String' - operations: 'Operation' + operations: 'DefaultOperation' revision: 'Int' state: 'AccountSnapshotState' } @@ -1144,7 +1156,7 @@ export interface NexusGenFieldTypeNames { id: 'String' lastModified: 'Date' name: 'String' - operations: 'Operation' + operations: 'DefaultOperation' revision: 'Int' state: 'BudgetStatementState' } @@ -1206,9 +1218,15 @@ export interface NexusGenFieldTypeNames { id: 'String' lastModified: 'Date' name: 'String' - operations: 'Operation' + operations: 'DefaultOperation' revision: 'Int' } + DefaultOperation: { // field return type name + hash: 'String' + index: 'Int' + timestamp: 'Date' + type: 'String' + } DocumentDriveState: { // field return type name icon: 'String' id: 'ID' @@ -1359,7 +1377,7 @@ export interface NexusGenFieldTypeNames { id: 'String' lastModified: 'Date' name: 'String' - operations: 'Operation' + operations: 'DefaultOperation' revision: 'Int' state: 'RealWorldAssetsState' } @@ -1398,7 +1416,7 @@ export interface NexusGenFieldTypeNames { id: 'String' lastModified: 'Date' name: 'String' - operations: 'Operation' + operations: 'DefaultOperation' revision: 'Int' state: 'ScopeFrameworkState' } @@ -1537,9 +1555,15 @@ export interface NexusGenFieldTypeNames { id: 'String' lastModified: 'Date' name: 'String' - operations: 'Operation' + operations: 'DefaultOperation' revision: 'Int' } + IOperation: { // field return type name + hash: 'String' + index: 'Int' + timestamp: 'Date' + type: 'String' + } IRealWorldAssetsState: { // field return type name accounts: 'Account' fixedIncomeTypes: 'FixedIncomeType' @@ -1549,12 +1573,6 @@ export interface NexusGenFieldTypeNames { spvs: 'Spv' transactions: 'GroupTransaction' } - Operation: { // field return type name - hash: 'String' - index: 'Int' - timestamp: 'Date' - type: 'String' - } System: { // field return type name auth: 'Auth' } @@ -1609,6 +1627,7 @@ export interface NexusGenAbstractTypeMembers { Asset: "Cash" | "FixedIncome" ElementComponents: "ArticleComponent" | "CoreComponent" | "ScopeComponent" | "SectionComponent" | "TypeSpecificationComponent" IDocument: "AccountSnapshot" | "BudgetStatement" | "DefaultDocument" | "RealWorldAssets" | "ScopeFramework" + IOperation: "DefaultOperation" IRealWorldAssetsState: "RealWorldAssetsPortfolio" | "RealWorldAssetsState" System: "SwitchboardDrive" | "SwitchboardHost" } @@ -1617,6 +1636,7 @@ export interface NexusGenTypeInterfaces { AccountSnapshot: "IDocument" BudgetStatement: "IDocument" DefaultDocument: "IDocument" + DefaultOperation: "IOperation" RealWorldAssets: "IDocument" RealWorldAssetsPortfolio: "IRealWorldAssetsState" RealWorldAssetsState: "IRealWorldAssetsState" @@ -1639,7 +1659,7 @@ export type NexusGenUnionNames = keyof NexusGenUnions; export type NexusGenObjectsUsingAbstractStrategyIsTypeOf = never; -export type NexusGenAbstractsUsingStrategyResolveType = "Asset" | "ElementComponents" | "IDocument" | "IRealWorldAssetsState" | "Operation" | "System"; +export type NexusGenAbstractsUsingStrategyResolveType = "Asset" | "ElementComponents" | "IDocument" | "IOperation" | "IRealWorldAssetsState" | "System"; export type NexusGenFeaturesConfig = { abstractTypeStrategies: { diff --git a/api/src/graphql/generated/drive/schema.graphql b/api/src/graphql/generated/drive/schema.graphql index 3ddf4fa4..87319f38 100644 --- a/api/src/graphql/generated/drive/schema.graphql +++ b/api/src/graphql/generated/drive/schema.graphql @@ -14,7 +14,7 @@ type AccountSnapshot implements IDocument { id: String! lastModified: Date! name: String! - operations: [Operation!]! + operations: [DefaultOperation!]! revision: Int! state: AccountSnapshotState! } @@ -100,7 +100,7 @@ type BudgetStatement implements IDocument { id: String! lastModified: Date! name: String! - operations: [Operation!]! + operations: [DefaultOperation!]! revision: Int! state: BudgetStatementState! } @@ -181,10 +181,17 @@ type DefaultDocument implements IDocument { id: String! lastModified: Date! name: String! - operations: [Operation!]! + operations: [DefaultOperation!]! revision: Int! } +type DefaultOperation implements IOperation { + hash: String! + index: Int! + timestamp: Date! + type: String! +} + type DocumentDriveState { icon: String id: ID! @@ -257,10 +264,17 @@ interface IDocument { id: String! lastModified: Date! name: String! - operations: [Operation!]! + operations: [DefaultOperation!]! revision: Int! } +interface IOperation { + hash: String! + index: Int! + timestamp: Date! + type: String! +} + interface IRealWorldAssetsState { accounts: [Account!]! fixedIncomeTypes: [FixedIncomeType!]! @@ -389,13 +403,6 @@ type Node { parentFolder: String } -interface Operation { - hash: String! - index: Int! - timestamp: Date! - type: String! -} - type OperationUpdate { hash: String! index: Int! @@ -427,7 +434,7 @@ type RealWorldAssets implements IDocument { id: String! lastModified: Date! name: String! - operations: [Operation!]! + operations: [DefaultOperation!]! revision: Int! state: RealWorldAssetsState! } @@ -472,7 +479,7 @@ type ScopeFramework implements IDocument { id: String! lastModified: Date! name: String! - operations: [Operation!]! + operations: [DefaultOperation!]! revision: Int! state: ScopeFrameworkState! } diff --git a/api/src/modules/document/resolvers.ts b/api/src/modules/document/resolvers.ts index d21a8d3e..1d25d9f0 100644 --- a/api/src/modules/document/resolvers.ts +++ b/api/src/modules/document/resolvers.ts @@ -7,14 +7,23 @@ const logger = getChildLogger({ msgPrefix: 'DOCUMENT RESOLVER' }); // todo: resolveType should be moved to somewhere else export const operationModelInterface = interfaceType({ - name: 'Operation', + name: 'IOperation', definition(t) { t.nonNull.string('type'); t.nonNull.int('index'); t.nonNull.field('timestamp', { type: GQLDateBase }); t.nonNull.string('hash'); }, - resolveType: (e) => 'Operation', + resolveType: (e) => { + return "DefaultOperation" + }, +}); + +export const operationModel = objectType({ + name: 'DefaultOperation', + definition(t) { + t.implements(operationModelInterface) + }, }); // todo: resolveType should be moved to somewhere else @@ -27,7 +36,7 @@ export const documentModelInterface = interfaceType({ t.nonNull.int('revision'); t.nonNull.field('created', { type: GQLDateBase }); t.nonNull.field('lastModified', { type: GQLDateBase }); - t.nonNull.list.nonNull.field('operations', { type: operationModelInterface }); + t.nonNull.list.nonNull.field('operations', { type: operationModel }); }, resolveType: (e) => { switch (e.documentType) {