Trouble making GraphQL unique global ids from PostgreSQL db records

System Information
  • Strapi Version: 3.4.2
  • Operating System: Pop OS 20.10
  • Database: PostgreSQL
  • Node Version: 12.18.2
  • NPM Version: 6.14.8
  • Yarn Version: 1.22.5

How can I make same ids of two different entities, say Authors and Posts, globally unique? I need this for my React Relay frontend. I tried to add prefixes in a controller like author.id = "author_" + author.id but Strapi gives error like id should be integer in "select * from posts where author = $1". I thought controller works with already fetched records and doesn’t use them for finding records.

1 Like

Yeah, hi everyone!

First of all, Strapi is great to use and I’ve already plugged it into our landing site. Thank you for this project!
But I’ve really stuck with this problem, so if anyone can give a hint to solve it would be great.

The database is PostgreSQL by the way.

This is the GraphQL type I use:

type Author {
id: ID!
created_at: DateTime!
updated_at: DateTime!
type_: ENUM_MENU_TYPE_!
name: String!
link: String
published_at: DateTime
posts(sort: String, limit: Int, start: Int, where: JSON): [Post]
}

OK, I tried to modify ids in a controller, a service and schema resolver. Basically I run through records, change author.id from eg ‘1’ to ‘author_1’ and post.id from ‘1’ to ‘post_1’. But I keep getting this error - select distinct "posts".* from "posts" where "posts"."id" in ($1, $2, $3) limit $4 - invalid input syntax for type integer: "post_1"

I know that ids are not integer after that, but why does it always try to run an SQL? The data I manipulate are already found with all params applied. Where is the point when all queries have already run, data is fetched and ready to be sent to client? So I can safely apply final changes to them.

Also, I hadn’t this error with v3.3.4. It started with v3.4.*. This is stopping me from upgrading to newer versions.

So any help would be appreciated. Thanks for reading!

1 Like

@domalak did you successfully used Relay without error like

"Warning: RelayResponseNormalizer: Invalid record `1`. Expected __typename to be consistent, but the record was assigned conflicting types `AddressEntity` and `OrganizerEntity`. The GraphQL server likely violated the globally unique id requirement by returning the same id for different objects.

Where you able to change Strapi entities ID ?