3

Doing this 👇

query {
  postsConnection(where: {
    status: PUBLISHED
  }) {
    aggregate {
      count
    }
    edges {
      cursor
      node {
        id
        slug
      }
    }
  }
}

gives me postsConnection of published posts.

The Post model has an array of Category enum in field categories. This is the Post in datamodel 👇

enum Category {
  TECH
  FIN
  DIGIMARK
  CODING
  TUTORIAL
  HOWTO
  WRITING
  INSPIRE
  SCIENCE
  POLITICS
  LIFESTYLE
}
type Post {
  id: ID!
  title: String!
  editorSerializedOutput: Json!
  editorCurrentContent: Json!
  editorHtml: String!
  updatedAt: DateTime!
  createdAt: DateTime!
  author: User
  authorId: String!
  categories: [Category!]!
  thumbnail: Json!
  status: PostStatus!
  slug: String!
}

My question is, what Prisma Query do I need to write to get PostConnection of posts in a specific category?

3
  • 1
    You already filter posts in your connection using status: PUBLISHED, you can do the same with categories Commented Mar 30, 2019 at 7:36
  • That's what the question is. I cannot do that with categories.. it is an array Commented Mar 30, 2019 at 10:14
  • Oh sorry, didn't quite understood the question, I added a better answer Commented Mar 30, 2019 at 10:17

1 Answer 1

1

Prisma doesn't yet allow filtering with Enum (see issue on github)

You can however make a to-many relation with a new Type Category that you can create

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.