Instance is not unique

SELF-SOLVED: Removed unique constraint on the allPlayers index

I get this error in PG:

{
  "errors": [
    {
      "message": "Instance is not unique.",
      "extensions": {
        "code": "instance not unique"
      }
    }
  ]
}

re: this entry in the schema:

type Player 
 {  rankingid : String!
    uid : String! @unique
    rank : Int!
    challengerid : String
}

and this function in PG:

mutation CreateNewPlayer {
  createNewPlayer(
    rankingid: "280892229782864389"
    uid: "280689785097421325"
    rank: 2
    challengerid: ""
  ) {
    _id
    rankingid
    uid
    rank
    challengerid
  }
}

the uid I have used here is unique, the rankingid is not.
I removed the @unique constraint that was previously on the rankingid in the schema and successfully uploaded it (checked).

  1. Why am I still getting the ‘Instance is not unique’ error?
  2. What else should I look into to resolve?
    thanks …

I have another instance of this issue.
I have the following:

mutation CreateARanking {
  createRanking(
    data: {
      active: true
      rankingname: "TestRnk6"
      rankingdesc: "U17"
      player: { connect: "287674108858073605" }
    }
  ) {
    _id
    rankingname
    rankingdesc
    player {
      _id
    }
  }
}

TestRnk6 doesn’t currently exist (AFAIK). It doesn’t appear in the Ranking collection.
Player _id = 287674108858073605 does already exist.

The previous answer (above) to this issue was to remove the unique constraint on allPlayers index.
However, AFAIK, there is no unique constraint on player.
Anyway, no allPlayers index has been automatically generated in the Fauna UI (there is allUsers and allRankings, but neither of them have unique constraints set either).
Player is defined as:

type Player {
rank: Int!
ranking: Ranking! @relation
challenger: User @relation
}

in the schema.
SOLVED, with thanks, by @ptpaterson:

Why does the CreateARanking mutation in PG give a
“message”: “Instance is not unique.”,
error message?
thanks …

Hi @FreeRoss ,

may you share the schema and I can give a try?

Thanks,

Luigi

Yes:

type User {
active: Boolean!
username: String!
description: String
email: String
mobile: String
playedAs: [Player!]! @relation
}

type Player {
active: Boolean!
rank: Int!
ranking: Ranking! @relation
challenger: User @relation
}

type Ranking {
active: Boolean!
rankingname: String!
rankingdesc: String
player: Player @relation
}

type Mutation {
  createNewUser(active: Boolean!, username : String!, password : String!, description: String, email: String, mobile: String): loginResult! @resolver(name: "create_new_user")
  loginUser(username: String!, password: String!): loginResult! @resolver(name: "login_user")
}

type Query {
  allUserNames: [String!]! @resolver(name: "all_user_names")
  allPlayerUIDs: [String!]! @resolver(name: "all_player_uids")
  allPlayerRanks: [Int!]! @resolver(name: "all_player_ranks")
  allPlayerChallengerUIDs: [String!]! @resolver(name: "all_player_challenger_uids")
  allPlayers: [Player] @resolver(name: "all_players")
  allRankings: [Ranking] @resolver(name: "all_rankings")
  allUsers: [User] @resolver(name: "all_users")
  gotPlayersByRankingId (rankingid: String!): [Player] @resolver(name: "got_players_byrankingid")
  gotRankingIdsByPlayer (uid: String!): [String] @resolver(name: "got_rankings_byplayerid")
}

type loginResult @embedded
{
  token : String
  logginUser : User
}

thx …

Uniqueness is enforced by Indexes, not the schema. If you removed the @unique contraint, Fauna will not automatically delete the Index that enforces the uniqueness.

You should expect there to be an Index that still exists called unique_Player_uid or something. Delete that if you do not want the uniqueness enforced anymore.

1 Like

@ptpaterson
Thanks yes, that fixed it.
Initially I deleted
unique_User_username
unique_Ranking_rankingname
as there was no equivalent for Player. However, I noticed neither of the above had the Unique constraint set by default anyway.
I then unset the Unique constraint on
player_ranking_by_player
and the document would then create in PG …