Skip to content

Commit

Permalink
feat: added support for operation context on graphql api
Browse files Browse the repository at this point in the history
  • Loading branch information
acaldas committed Apr 24, 2024
1 parent b2a7617 commit 86a2f31
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ model Operation {
attachments Attachment[]
syncId String?
clipboard Boolean? @default(false)
context Json?
SyncronizationUnit SyncronizationUnit? @relation(fields: [syncId, driveId], references: [id, driveId], onDelete: Cascade)
Expand Down
72 changes: 72 additions & 0 deletions api/src/graphql/generated/drive/nexus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,25 @@ export interface NexusGenInputs {
documentType?: Array<string | null> | null; // [String]
scope?: Array<string | null> | null; // [String]
}
InputOperationContext: { // input type
signer?: NexusGenInputs['InputOperationSigner'] | null; // InputOperationSigner
}
InputOperationSigner: { // input type
app: NexusGenInputs['InputOperationSignerApp']; // InputOperationSignerApp!
signature: string; // String!
user: NexusGenInputs['InputOperationSignerUser']; // InputOperationSignerUser!
}
InputOperationSignerApp: { // input type
key: string; // String!
name: string; // String!
}
InputOperationSignerUser: { // input type
address: string; // String!
chainId: number; // Int!
networkId: string; // String!
}
InputOperationUpdate: { // input type
context?: NexusGenInputs['InputOperationContext'] | null; // InputOperationContext
hash: string; // String!
index: number; // Int!
input: string; // String!
Expand Down Expand Up @@ -380,7 +398,25 @@ export interface NexusGenObjects {
name: string; // String!
parentFolder?: string | null; // String
}
OperationContext: { // root type
signer?: NexusGenRootTypes['OperationSigner'] | null; // OperationSigner
}
OperationSigner: { // root type
app: NexusGenRootTypes['OperationSignerApp']; // OperationSignerApp!
signature: string; // String!
user: NexusGenRootTypes['OperationSignerUser']; // OperationSignerUser!
}
OperationSignerApp: { // root type
key: string; // String!
name: string; // String!
}
OperationSignerUser: { // root type
address: string; // String!
chainId: number; // Int!
networkId: string; // String!
}
OperationUpdate: { // root type
context?: NexusGenRootTypes['OperationContext'] | null; // OperationContext
hash: string; // String!
index: number; // Int!
input: string; // String!
Expand Down Expand Up @@ -853,7 +889,25 @@ export interface NexusGenFieldTypes {
name: string; // String!
parentFolder: string | null; // String
}
OperationContext: { // field return type
signer: NexusGenRootTypes['OperationSigner'] | null; // OperationSigner
}
OperationSigner: { // field return type
app: NexusGenRootTypes['OperationSignerApp']; // OperationSignerApp!
signature: string; // String!
user: NexusGenRootTypes['OperationSignerUser']; // OperationSignerUser!
}
OperationSignerApp: { // field return type
key: string; // String!
name: string; // String!
}
OperationSignerUser: { // field return type
address: string; // String!
chainId: number; // Int!
networkId: string; // String!
}
OperationUpdate: { // field return type
context: NexusGenRootTypes['OperationContext'] | null; // OperationContext
hash: string; // String!
index: number; // Int!
input: string; // String!
Expand Down Expand Up @@ -1352,7 +1406,25 @@ export interface NexusGenFieldTypeNames {
name: 'String'
parentFolder: 'String'
}
OperationContext: { // field return type name
signer: 'OperationSigner'
}
OperationSigner: { // field return type name
app: 'OperationSignerApp'
signature: 'String'
user: 'OperationSignerUser'
}
OperationSignerApp: { // field return type name
key: 'String'
name: 'String'
}
OperationSignerUser: { // field return type name
address: 'String'
chainId: 'Int'
networkId: 'String'
}
OperationUpdate: { // field return type name
context: 'OperationContext'
hash: 'String'
index: 'Int'
input: 'String'
Expand Down
44 changes: 44 additions & 0 deletions api/src/graphql/generated/drive/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,29 @@ input InputListenerFilter {
scope: [String]
}

input InputOperationContext {
signer: InputOperationSigner
}

input InputOperationSigner {
app: InputOperationSignerApp!
signature: String!
user: InputOperationSignerUser!
}

input InputOperationSignerApp {
key: String!
name: String!
}

input InputOperationSignerUser {
address: String!
chainId: Int!
networkId: String!
}

input InputOperationUpdate {
context: InputOperationContext
hash: String!
index: Int!
input: String!
Expand Down Expand Up @@ -404,7 +426,29 @@ type Node {
parentFolder: String
}

type OperationContext {
signer: OperationSigner
}

type OperationSigner {
app: OperationSignerApp!
signature: String!
user: OperationSignerUser!
}

type OperationSignerApp {
key: String!
name: String!
}

type OperationSignerUser {
address: String!
chainId: Int!
networkId: String!
}

type OperationUpdate {
context: OperationContext
hash: String!
index: Int!
input: String!
Expand Down
73 changes: 71 additions & 2 deletions api/src/modules/document-drive/drive-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from 'nexus';
import { systemType } from '../system';
import {
ListenerRevision as IListenerRevision, UpdateStatus as IUpdateStatus, StrandUpdate,
ListenerRevision as IListenerRevision, UpdateStatus as IUpdateStatus,
} from 'document-drive';
import { Operation, OperationScope } from 'document-model/document';
import stringify from 'json-stringify-deterministic';
Expand Down Expand Up @@ -84,6 +84,39 @@ export const ListenerRevision = objectType({
},
});

export const OperationSignerUser = objectType({
name: 'OperationSignerUser',
definition(t) {
t.nonNull.string('address');
t.nonNull.string('networkId');
t.nonNull.int('chainId');
},
});

export const OperationSignerApp = objectType({
name: 'OperationSignerApp',
definition(t) {
t.nonNull.string('name');
t.nonNull.string('key');
},
});

export const OperationSigner = objectType({
name: 'OperationSigner',
definition(t) {
t.nonNull.field('user', { type: OperationSignerUser });
t.nonNull.field('app', { type: OperationSignerApp });
t.nonNull.string('signature');
}
});

export const OperationContext = objectType({
name: 'OperationContext',
definition(t) {
t.field('signer', { type: OperationSigner });
}
})

export const OperationUpdate = objectType({
name: 'OperationUpdate',
definition(t) {
Expand All @@ -93,9 +126,43 @@ export const OperationUpdate = objectType({
t.nonNull.string('input');
t.nonNull.string('hash');
t.nonNull.string('timestamp');
t.field('context', { type: OperationContext });
},
});

export const InputOperationSignerUser = inputObjectType({
name: 'InputOperationSignerUser',
definition(t) {
t.nonNull.string('address');
t.nonNull.string('networkId');
t.nonNull.int('chainId');
},
});

export const InputOperationSignerApp = inputObjectType({
name: 'InputOperationSignerApp',
definition(t) {
t.nonNull.string('name');
t.nonNull.string('key');
},
});

export const InputOperationSigner = inputObjectType({
name: 'InputOperationSigner',
definition(t) {
t.nonNull.field('user', { type: InputOperationSignerUser });
t.nonNull.field('app', { type: InputOperationSignerApp });
t.nonNull.string('signature');
}
});

export const InputOperationContext = inputObjectType({
name: 'InputOperationContext',
definition(t) {
t.field('signer', { type: InputOperationSigner });
}
})

export const InputOperationUpdate = inputObjectType({
name: 'InputOperationUpdate',
definition(t) {
Expand All @@ -105,6 +172,7 @@ export const InputOperationUpdate = inputObjectType({
t.nonNull.string('input');
t.nonNull.string('hash');
t.nonNull.string('timestamp');
t.field('context', { type: InputOperationContext });
},
});

Expand Down Expand Up @@ -190,7 +258,7 @@ export const syncType = objectType({
listenerId,
since,
);
return result.map((e: StrandUpdate) => ({
return result.map((e) => ({
driveId: e.driveId,
documentId: e.documentId,
scope: e.scope,
Expand All @@ -203,6 +271,7 @@ export const syncType = objectType({
hash: o.hash,
timestamp: o.timestamp,
type: o.type,
context: o.context,
})),
}));
} catch (e) {
Expand Down

0 comments on commit 86a2f31

Please sign in to comment.