diff --git a/packages/daf-core/src/entities/claim.ts b/packages/daf-core/src/entities/claim.ts index fd0654fb2..d8a60e134 100644 --- a/packages/daf-core/src/entities/claim.ts +++ b/packages/daf-core/src/entities/claim.ts @@ -3,11 +3,7 @@ import { Column, BaseEntity, ManyToOne, - JoinTable, PrimaryColumn, - OneToMany, - ManyToMany, - BeforeInsert, } from 'typeorm' import { Identity } from './identity' import { Credential } from './credential' @@ -19,13 +15,17 @@ export class Claim extends BaseEntity { @ManyToOne( type => Identity, - identity => identity.issuedPresentations, + identity => identity.issuedPresentations, { + eager: true + } ) issuer: Identity @ManyToOne( type => Identity, - identity => identity.receivedPresentations, + identity => identity.receivedPresentations, { + eager: true + } ) subject: Identity diff --git a/packages/daf-core/src/entities/credential.ts b/packages/daf-core/src/entities/credential.ts index b3287d8d7..491ebcc71 100644 --- a/packages/daf-core/src/entities/credential.ts +++ b/packages/daf-core/src/entities/credential.ts @@ -4,11 +4,9 @@ import { Column, BaseEntity, ManyToOne, - JoinTable, PrimaryColumn, OneToMany, ManyToMany, - BeforeInsert, } from 'typeorm' import { Identity } from './identity' import { Message } from './message' @@ -63,6 +61,7 @@ export class Credential extends BaseEntity { identity => identity.issuedCredentials, { cascade: ['insert'], + eager: true }, ) issuer: Identity @@ -72,6 +71,7 @@ export class Credential extends BaseEntity { identity => identity.receivedCredentials, { cascade: ['insert'], + eager: true }, ) subject: Identity @@ -103,6 +103,9 @@ export class Credential extends BaseEntity { ) presentations: Presentation[] - @ManyToMany(type => Message) + @ManyToMany( + type => Message, + message => message.credentials + ) messages: Message[] } diff --git a/packages/daf-core/src/entities/message.ts b/packages/daf-core/src/entities/message.ts index ea8e058dc..1fed74937 100644 --- a/packages/daf-core/src/entities/message.ts +++ b/packages/daf-core/src/entities/message.ts @@ -5,7 +5,6 @@ import { ManyToOne, ManyToMany, PrimaryGeneratedColumn, - OneToMany, JoinTable, CreateDateColumn, UpdateDateColumn, @@ -72,6 +71,7 @@ export class Message extends BaseEntity { { nullable: true, cascade: ['insert'], + eager: true }, ) from?: Identity @@ -82,6 +82,7 @@ export class Message extends BaseEntity { { nullable: true, cascade: ['insert'], + eager: true }, ) to?: Identity @@ -99,9 +100,11 @@ export class Message extends BaseEntity { @JoinTable() presentations: Presentation[] - @ManyToMany(type => Credential, { - cascade: true, - }) + @ManyToMany( + type => Credential, + credential => credential.messages, + { cascade: true } + ) @JoinTable() credentials: Credential[] diff --git a/packages/daf-core/src/entities/presentation.ts b/packages/daf-core/src/entities/presentation.ts index 70a294356..ad1984625 100644 --- a/packages/daf-core/src/entities/presentation.ts +++ b/packages/daf-core/src/entities/presentation.ts @@ -35,6 +35,7 @@ export class Presentation extends BaseEntity { identity => identity.issuedPresentations, { cascade: ['insert'], + eager: true }, ) issuer: Identity @@ -44,6 +45,7 @@ export class Presentation extends BaseEntity { identity => identity.receivedPresentations, { cascade: ['insert'], + eager: true }, ) audience: Identity diff --git a/packages/daf-core/src/graphql/graphql-core.ts b/packages/daf-core/src/graphql/graphql-core.ts index f1f3df1cc..930a45ddf 100644 --- a/packages/daf-core/src/graphql/graphql-core.ts +++ b/packages/daf-core/src/graphql/graphql-core.ts @@ -29,7 +29,6 @@ const messages = async ( }}, ) => { const options = { - relations: ['from', 'to'], where: {} } @@ -54,7 +53,7 @@ const claims = async ( }}, ) => { const options = { - relations: ['issuer', 'subject', 'credential'], + relations: ['credential'], where: {} } @@ -69,41 +68,47 @@ const claims = async ( } export const resolvers = { + Mutation: { + saveNewMessage, + }, + + Query: { + messages, + message: async (_: any, { id }) => Message.findOne(id), + identity: async (_: any, { did }) => Identity.findOne(did), + credential: async (_: any, { hash }) => Credential.findOne(hash), + identities: async () => Identity.find(), + claims, + }, + Identity: { - sentMessages: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['sentMessages', 'sentMessages.from', 'sentMessages.to']})).sentMessages, - receivedMessages: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedMessages', 'receivedMessages.from', 'receivedMessages.to']})).receivedMessages, - issuedPresentations: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedPresentations', 'issuedPresentations.issuer', 'issuedPresentations.audience']})).issuedPresentations, - receivedPresentations: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedPresentations', 'receivedPresentations.issuer', 'receivedPresentations.audience']})).receivedPresentations, - issuedCredentials: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedCredentials', 'issuedCredentials.issuer', 'issuedCredentials.subject']})).issuedCredentials, - receivedCredentials: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedCredentials', 'receivedCredentials.issuer', 'receivedCredentials.subject']})).receivedCredentials, - issuedClaims: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedClaims', 'issuedClaims.issuer', 'issuedClaims.subject']})).issuedClaims, - receivedClaims: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedClaims', 'receivedClaims.issuer', 'receivedClaims.subject']})).receivedClaims, + sentMessages: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['sentMessages']})).sentMessages, + receivedMessages: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedMessages']})).receivedMessages, + issuedPresentations: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedPresentations']})).issuedPresentations, + receivedPresentations: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedPresentations']})).receivedPresentations, + issuedCredentials: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedCredentials']})).issuedCredentials, + receivedCredentials: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedCredentials']})).receivedCredentials, + issuedClaims: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['issuedClaims']})).issuedClaims, + receivedClaims: async (identity: Identity) => (await Identity.findOne(identity.did, { relations: ['receivedClaims']})).receivedClaims, }, Credential: { - claims: async (credential: Credential) => Claim.find({ where: { credential: credential.hash}, relations: ['issuer', 'subject', 'credential'] }), - messages: async (credential: Credential) => (await Credential.findOne(credential.hash, { relations: ['messages', 'messages.from', 'messages.to']}))?.messages, - presentations: async (credential: Credential) => (await Credential.findOne(credential.hash, { relations: ['presentations', 'presentations.issuer', 'presentations.audience']})).presentations, + claims: async (credential: Credential) => Claim.find({ where: { credential: credential.hash}, relations: ['credential'] }), + messages: async (credential: Credential) => (await Credential.findOne(credential.hash, { relations: ['messages']})).messages, + presentations: async (credential: Credential) => (await Credential.findOne(credential.hash, { relations: ['presentations']})).presentations, }, + Presentation: { - credentials: async (presentation: Presentation) => (await Presentation.findOne(presentation.hash, { relations: ['credentials', 'credentials.issuer', 'credentials.subject']})).credentials, - messages: async (presentation: Presentation) => (await Presentation.findOne(presentation.hash, { relations: ['messages', 'messages.from', 'messages.to']})).messages + credentials: async (presentation: Presentation) => (await Presentation.findOne(presentation.hash, { relations: ['credentials']})).credentials, + messages: async (presentation: Presentation) => (await Presentation.findOne(presentation.hash, { relations: ['messages']})).messages }, + Message: { - presentations: async (message: Message) => (await Message.findOne(message.id, { relations: ['presentations', 'presentations.issuer', 'presentations.audience']})).presentations, - credentials: async (message: Message) => (await Message.findOne(message.id, { relations: ['credentials', 'credentials.issuer', 'credentials.subject']})).credentials, - }, - Query: { - messages, - message: async (_: any, { id }) => Message.findOne(id, { relations: ['from', 'to'] }), - identity: async (_: any, { did }) => Identity.findOne(did), - credential: async (_: any, { hash }) => Credential.findOne(hash, { relations: ['issuer', 'subject'] }), - identities: async () => Identity.find(), - claims, - }, - Mutation: { - saveNewMessage, + presentations: async (message: Message) => (await Message.findOne(message.id, { relations: ['presentations']})).presentations, + credentials: async (message: Message) => (await Message.findOne(message.id, { relations: ['credentials']})).credentials, }, + + } export const typeDefs = `