Building resolvers for linksConnection query and other nested relations

prisma

#1

I am trying to figure out how to setup the resolvers for a Connection Type and haven’t been able to find any good examples after searching for a few days and trying to follow several blog posts and Prisma docs explaining basic ways of setting up resolvers. Being able to use Connections with edges, nodes, and cursors for paginations are a must for me, so I would really like to be able to use Prisma for my project.

I am using the following types in my schema.graphql that were generated by the prisma client.

type Query {
  linksConnection(
    skip: Int
    after: String
    before: String
    first: Int
    last: Int
  ): LinkConnection!
}
type LinkConnection {
  pageInfo: PageInfo!
  edges: [LinkEdge]!
  aggregate: AggregateLink!
}
type PageInfo {
  hasNextPage: Boolean!
  hasPreviousPage: Boolean!
  startCursor: String
  endCursor: String
}
type LinkEdge {
  node: Link!
  cursor: String!
}
type Link {
  id: ID!
  createdAt: DateTime!
  description: String!
  url: String!
}
type AggregateLink {
  count: Int!
}

I have attempted to implement the resolvers and can’t figure it out what resolvers I need with the nested type relations or how to properly define them?

I have looked at the following links/issues as well as several others:
https://www.prisma.io/tutorials/a-guide-to-common-resolver-patterns-ct08
https://www.prisma.io/blog/graphql-server-basics-the-schema-ac5e2950214e
https://www.prisma.io/forum/t/prisma-client-field-experiencesconnection-of-type-experienceconnection-must-have-a-sub-selection/4632
https://www.prisma.io/forum/t/how-to-write-nested-relation-connection-subfield-resolvers/3768/2
https://www.prisma.io/forum/t/handling-connections-with-prisma-bindings/3723

I noticed from console.log that the context.prisma.linksConnection() method has a pageInfo(), edges(), and aggregate() method mapped on its instance.

Below is what I currently have, and I’ve tried several other thins as well, but continue to get the following error “message”: "Field ‘linksConnection’ of type ‘LinkConnection’ must have a sub selection

From what I’ve researched, I believe this error has to do with my resolvers not being set up or defined properly.

I am using the following dependencies:

    "graphql-yoga": "^1.16.9",
    "prisma-client-lib": "1.23.0-test.2"

And have my resolvers most likely defined incorrectly below:

const resolvers = {
  Query: {
    linksConnection: async (root, args, context, info) => {
      return context.prisma.linksConnection(
        {},
        info
      )
    }
  },
  LinkConnection: {
    pageInfo: async (root, args, context, info) => {
      return context.prisma.linksConnection().pageInfo()
    },
    edges: async (root, args, context, info) => {
      return context.prisma.linksConnection().edges()
    },
    aggregate: async (root, args, context, info) => {
      return context.prisma.linksConnection().aggregate()
    },
  },
  LinkEdge: {
    node: async (root, args, context, info) => {
      return context.prisma.link()
    },
  },
  Node: {
    __resolveType (obj, ctx, info) {
      return obj.__typename
    }
  },
};

#2

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.