meteorenthusiast
meteorenthusiast

Reputation: 11

Graphcool: how to create multifield unique constraints?

I'd like to create multi field constraint. In the same way in which is possible in SQL for instance by specifying:

CREATE TABLE …. UNIQUE(field1, field2);

So that what is unique is the combination of fields.

Is it possible to enforce this constraint in Graphcool?

Upvotes: 1

Views: 32

Answers (1)

Zaal Kavelashvili
Zaal Kavelashvili

Reputation: 558

You can use permission queries to achieve custom checks. For example you dont want that user be able to add multiple comments on Post, so you want that Comment.post_id and Comment.user_id be unique. Use this permission query for this

  SomeProposalExists(filter: {
    post: {
      id_not: $input_postId
    }
    user: {
      id_not: $input_userId
    }
  })

Upvotes: 0

Related Questions