Skip to content

Commit

Permalink
feat: Query for single credential by id(hash)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Healy committed Jan 24, 2020
1 parent 198b47e commit 1283ce5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/daf-data-store/src/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,28 @@ export class DataStore {
return runMigrations(this.db)
}

async findCredential(id: string) {
const query = sql
.select('rowid', '*')
.from('verifiable_credentials')
.where({ hash: id })
.toParams()

const rows = await this.db.rows(query.text, query.values)

const mapped = rows.map((row: any) => ({
rowId: `${row.rowid}`,
hash: row.hash,
iss: { did: row.iss },
sub: { did: row.sub },
jwt: row.jwt,
nbf: row.nbf,
iat: row.iat,
}))

return mapped[0]
}

async findCredentials({ iss, sub }: { iss?: string; sub?: string }) {
let where = {}

Expand Down
3 changes: 3 additions & 0 deletions packages/daf-data-store/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export const resolvers = {
const res = await dataStore.findCredentials({ iss, sub })
return res
},
credential: async (_: any, { id }: { id: string }, { dataStore }: Context) =>
dataStore.findCredential(id),
},
Mutation: {
deleteMessage: async (_: any, { id }: { id: string }, { dataStore }: Context) =>
Expand All @@ -102,6 +104,7 @@ export const typeDefs = `
messages(sender: ID, reveiver: ID, threadId: String, limit: Int): [Message]
message(id: ID!): Message!
credentials(iss: ID, sub: ID): [VerifiableClaim]
credential(id:ID!): VerifiableClaim!
}
extend type Mutation {
Expand Down

0 comments on commit 1283ce5

Please sign in to comment.