Thursday, 30 May 2019

Nexus-prisma: order nested connections

What is the best way to keep order of nested objects in the schema.

My schema:

type Article {
  id: ID! @id
  pages: [Page!]!
}

type Page {
  id: ID! @id
}

This is how I'm trying to sort the pages(unsuccessfully):

  updateArticle({
    variables: {
      aricle.id,
      data: {
        pages: {
          connect: reorderPages(aricle.pages)
        }
      }
    }

The resolver:

 t.field("updateArticle", {
      type: "Article",
      args: {
        id: idArg(),
        data: t.prismaType.updateArticle.args.data
      },
      resolve: (_, { id, data }) => {
        return ctx.prisma.updateArticle({
          where: { id },
          data
        });
      }
    });

I understand why this approach is wrong. I guess that the order should be written in the database by an order index in the connection table. I don't know how to process that by GraphQL/Nexus/Prisma/MySQL.



from Nexus-prisma: order nested connections

No comments:

Post a Comment