Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/typeorm gql #118

Merged
merged 8 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 37 additions & 17 deletions docs/Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ console.log(`🚀 Server ready at ${info.url}`)
## Typescript

```typescript
const providers = await core.identityManager.getIdentityProviders()
const identity = await core.identityManager.createIdentity(providers[0].type)
const identity = await agent.identityManager.createIdentity()
```

## GraphQL
Expand Down Expand Up @@ -346,10 +345,12 @@ const memberVc = memberClaims[0]?.credential

```typescript
const input = {
issuer: ['did:ethr:567', 'did:ethr:659'],
subject: 'did:example:1234',
type: 'member',
value: 'status',
where: [
{ column: 'issuer', value: ['did:ethr:567', 'did:ethr:659'] },
{ column: 'subject', value: ['did:example:1234'] },
{ column: 'type', value: ['member'] },
{ column: 'value', value: ['status'] },
],
}
```

Expand Down Expand Up @@ -643,7 +644,7 @@ Fields
import { Identity } from 'daf-core'
const dbConnection = await agent.dbConnection
const identity = await dbConnection.getRepository(Identity).findOne('did:example:123', {
relations: ['receivedClaims'],
relations: ['issuedClaims'],
})

console.log(identity.receivedClaims) // [Claim(type: 'name', value: 'Alice'), ...]
Expand All @@ -652,14 +653,19 @@ console.log(identity.receivedClaims) // [Claim(type: 'name', value: 'Alice'), ..
### GraphQL

```graphql
query {
identity(did: "did:example:123") {
query identity($did: String!) {
identity(did: $did) {
did
shortDid
name: latestClaimValue(type: "name")
profileImage: latestClaimValue(type: "profileImage")
receivedClaims {
type
value
profilePicture: latestClaimValue(type: "profilePicture")
}
issuedClaims: claims(input: { where: [{ column: issuer, value: [$did] }] }) {
subject {
did
}
type
value
}
}
```
Expand Down Expand Up @@ -702,7 +708,7 @@ const messages = await dbConnection.getRepository(Message).find({

```graphql
query {
messages(input: { type: "sdr", options: { take: 5 } }) {
messages(input: { where: [{ column: type, value: "sdr" }], take: 5 }) {
id
from {
did
Expand Down Expand Up @@ -747,7 +753,14 @@ const presentations = await dbConnection.getRepository(Presentation).find({

```graphql
query {
presentations(input: { type: "VerifiablePresentation,KYC", issuer: "did:web:example.com" }) {
presentations(
input: {
where: [
{ column: issuer, value: "did:web:example.com" }
{ column: type, value: "VerifiablePresentation,KYC" }
]
}
) {
audience {
did
}
Expand Down Expand Up @@ -801,7 +814,14 @@ const credentials = await dbConnection.getRepository(Credential).find({

```graphql
query {
credentials(input: { subject: "did:web:example.com", expirationDateLessThan: "2020-12-12T10:00:00Z" }) {
credentials(
input: {
where: [
{ column: subject, value: "did:web:example.com" }
{ column: expirationDate, value: "2020-12-12T10:00:00Z", op: LessThan }
]
}
) {
issuer {
did
}
Expand Down Expand Up @@ -870,7 +890,7 @@ console.log(claims)

```graphql
query {
claims(input: { type: "address" }) {
claims(input: { where: [{ column: type, value: "address" }] }) {
type
value
isObj
Expand Down
3 changes: 3 additions & 0 deletions packages/daf-core/src/entities/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export class Credential extends BaseEntity {
)
subject?: Identity

@Column({ nullable: true })
id?: String

@Column()
issuanceDate: Date

Expand Down
16 changes: 15 additions & 1 deletion packages/daf-core/src/entities/identity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { Entity, Column, PrimaryColumn, BaseEntity, OneToMany, ManyToMany } from 'typeorm'
import {
Entity,
Column,
PrimaryColumn,
BaseEntity,
OneToMany,
CreateDateColumn,
UpdateDateColumn,
} from 'typeorm'
import { Key } from './key'
import { Message } from './message'
import { Presentation } from './presentation'
Expand All @@ -14,6 +22,12 @@ export class Identity extends BaseEntity {
@Column({ nullable: true })
provider: string

@CreateDateColumn()
saveDate: Date

@UpdateDateColumn()
updateDate: Date

@Column({ nullable: true })
controllerKeyId: string

Expand Down
13 changes: 11 additions & 2 deletions packages/daf-core/src/entities/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import {
BaseEntity,
ManyToOne,
ManyToMany,
PrimaryGeneratedColumn,
PrimaryColumn,
JoinTable,
CreateDateColumn,
UpdateDateColumn,
BeforeInsert,
} from 'typeorm'
import { blake2bHex } from 'blakejs'
import { Identity } from './identity'
import { Presentation } from './presentation'
import { Credential } from './credential'
Expand All @@ -30,7 +32,14 @@ export class Message extends BaseEntity {
}
}

@PrimaryGeneratedColumn('uuid')
@BeforeInsert()
setId() {
if (!this.id) {
this.id = blake2bHex(this.raw)
}
}

@PrimaryColumn()
id: string

@CreateDateColumn()
Expand Down
7 changes: 5 additions & 2 deletions packages/daf-core/src/entities/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class Presentation extends BaseEntity {
identity => identity.issuedPresentations,
{
cascade: ['insert'],
eager: true
eager: true,
},
)
issuer: Identity
Expand All @@ -45,11 +45,14 @@ export class Presentation extends BaseEntity {
identity => identity.receivedPresentations,
{
cascade: ['insert'],
eager: true
eager: true,
},
)
audience: Identity

@Column({ nullable: true })
id?: String

@Column()
issuanceDate: Date

Expand Down
2 changes: 1 addition & 1 deletion packages/daf-core/src/graphql/graphql-base-type-defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const baseTypeDefs = `
type Mutation

type Identity {
did: ID!
did: String!
provider: String
}

Expand Down
Loading