Skip to content

Commit

Permalink
feat: GQL count queries
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Apr 15, 2020
1 parent 786b42e commit 9e859c1
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions packages/daf-core/src/graphql/graphql-core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,32 @@ const presentations = async (_: any, args: FindArgs, ctx: Context) => {
return (await ctx.agent.dbConnection).getRepository(Presentation).find(options)
}

const presentationsCount = async (_: any, args: FindArgs, ctx: Context) => {
const options = transformFindInput(args.input)
return (await ctx.agent.dbConnection).getRepository(Presentation).count(options)
}

const credentials = async (_: any, args: FindArgs, ctx: Context) => {
const options = transformFindInput(args.input)
return (await ctx.agent.dbConnection).getRepository(Credential).find(options)
}

const credentialsCount = async (_: any, args: FindArgs, ctx: Context) => {
const options = transformFindInput(args.input)
return (await ctx.agent.dbConnection).getRepository(Credential).count(options)
}

const claims = async (_: any, args: FindArgs, ctx: Context) => {
const options = transformFindInput(args.input)
options['relations'] = ['credential']
return (await ctx.agent.dbConnection).getRepository(Claim).find(options)
}

const claimsCount = async (_: any, args: FindArgs, ctx: Context) => {
const options = transformFindInput(args.input)
return (await ctx.agent.dbConnection).getRepository(Claim).count(options)
}

export const resolvers = {
Mutation: {
handleMessage: async (
Expand All @@ -167,12 +182,15 @@ export const resolvers = {
presentation: async (_: any, { hash }, ctx: Context) =>
(await ctx.agent.dbConnection).getRepository(Presentation).findOne(hash),
presentations,
presentationsCount,
credential: async (_: any, { hash }, ctx: Context) =>
(await ctx.agent.dbConnection).getRepository(Credential).findOne(hash),
credentials,
credentialsCount,
claim: async (_: any, { hash }, ctx: Context) =>
(await ctx.agent.dbConnection).getRepository(Claim).findOne(hash, { relations: ['credential'] }),
claims,
claimsCount,
},

Identity: {
Expand Down Expand Up @@ -421,10 +439,13 @@ export const typeDefs = `
messagesCount(input: MessagesInput): Int
presentation(hash: ID!): Presentation
presentations(input: PresentationsInput): [Presentation]
presentationsCount(input: PresentationsInput): Int
credential(hash: ID!): Credential
credentials(input: CredentialsInput): [Credential]
credentialsCount(input: CredentialsInput): Int
claim(hash: ID!): Claim
claims(input: ClaimsInput): [Claim]
claimsCount(input: ClaimsInput): Int
}
input MetaDataInput {
Expand Down

0 comments on commit 9e859c1

Please sign in to comment.