Skip to content

Commit

Permalink
fix: IdentityStore saving services
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Sep 14, 2020
1 parent ce2960c commit 9a35ee9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
17 changes: 17 additions & 0 deletions __tests__/shared/webDidFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,23 @@ export default (testContext: {
serviceIdentityKey = serviceIdentity.keys[0]
})

it('should add service endpoint', async () => {
const service = {
id: 'did:web:example.com#1',
type: 'Messaging',
description: 'Post any RAW message here',
serviceEndpoint: 'https://example.com/messaging',
}

await agent.identityManagerAddService({
did: 'did:web:example.com',
service,
})

const testIdentity = await agent.identityManagerGetIdentity({ did: 'did:web:example.com' })
expect(testIdentity.services[0]).toEqual(service)
})

it('should get existing service identity', async () => {
const testIdentity = await agent.identityManagerGetOrCreateIdentity({
provider: 'did:web',
Expand Down
22 changes: 22 additions & 0 deletions packages/daf-graphql/src/methods/identity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,35 @@ export const identityManagerDeleteIdentity: IAgentGraphQLMethod = {
`,
}

export const identityManagerAddService: IAgentGraphQLMethod = {
type: 'Mutation',
query: `
mutation identityManagerAddService($did: String, $service: ServiceInput) {
identityManagerAddService(did: $did, service: $service)
}
`,
typeDef: `
scalar AddServiceResult
input ServiceInput {
id: String!
type: String!
serviceEndpoint: String!
description: String
}
extend type Mutation {
identityManagerAddService(did: String, service: ServiceInput): AddServiceResult
}
`,
}

export const supportedMethods: Record<string, IAgentGraphQLMethod> = {
identityManagerGetProviders,
identityManagerGetIdentities,
identityManagerGetIdentity,
identityManagerCreateIdentity,
identityManagerGetOrCreateIdentity,
identityManagerDeleteIdentity,
identityManagerAddService,
// TODO identityManagerImportIdentity
}

Expand Down
4 changes: 3 additions & 1 deletion packages/daf-typeorm/src/entities/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ export class Identity extends BaseEntity {
//@ts-ignore
keys: Key[]

@OneToMany((type) => Service, (service) => service.identity)
@OneToMany((type) => Service, (service) => service.identity, {
cascade: ['insert'],
})
//@ts-ignore
services: Service[]

Expand Down

0 comments on commit 9a35ee9

Please sign in to comment.