Access Connection info (e.g. count) for type in a resolver?


Say I have a Post type and therefore I have a generated PostConnection type.

In my “posts” resolver I want to not only return post data (title, content etc) but also some meta information e.g. The total number of posts.

I have tried the following in my resolver:

let connection = await ctx.db.query.postsConnection(
  { },
let count = connection.aggregate.count

But I get the error:

Field “postsConnection” of type “PostConnection!” must have a selection of subfields. Did you mean “postsConnection { … }”?

This makes sense logically e.g. when querying PostConnection I need to return the aggregate or postInfo etc.

Any idea how to get this information or why this does not work?



Have a look at the Prisma docs Queries: Connection queries


Thanks @meep.

I’m familiar with how to query the connection types via GraphQL query syntax directly as shown in the docs but am trying to use the generated Prisma schema API with Typescript. Sorry I didn’t make that clear.

Here are some connection queries in the graphcool/graphql-server-example:


What are you passing in as info?

Is it similar to?

query {
  postsConnection(where: {
    title_contains: "GraphQL"
  }) {
    aggregate {


Agreed with @meep, the following should work:

let connection = await ctx.db.query.postsConnection(
  { },
  `{ aggregate { count } } }`,
let count = connection.aggregate.count

The way you wrote it, you make the info object depend on the query coming in from the client. Only if that includes the aggregate { count } part is your code valid.

Check out this blog article, I’ve found it super useful in understanding the info object and all its intricacies :slightly_smiling_face: