web-ridge / gqlgen-sqlboiler

This is a plugin for gqlgen to generate converts + filter queries and resolvers for sqlboiler
MIT License
74 stars 13 forks source link

Record composite primary key incorrectly referred to by non existent single field "ID" and input translation not generated #55

Closed orible closed 7 months ago

orible commented 3 years ago

Model with composite primary key incorrectly referred to by non existent single field "ID"

Take a model with two primary keys called "ThreadVote" ThreadID UserID CreatedAt Vote

Parts of the generated code incorrectly assumes that it has a single primary key called ID,

For example instead of

dm.ThreadVoteWhere.ThreadID AND dm.ThreadVoteWhere.UserID

It refers to the table by

dm.ThreadVoteWhere.ID.EQ(dbID)

Key translations in mutations are also not generated

For example;

dbID := ThreadVoteID(id)

Does not exist.

orible commented 3 years ago

In this example, it's a UNIQUE 1:1 relationship mapping the user's vote value, to the target thread.

The SQL tables are correctly referenced in foreign keys and the sqlboiler relationship is correct.

RichardLindhout commented 3 years ago

Ah yeah that does not work indeed.

I would recommend adding an auto increment id to your table.

We need unique id's for Relay in our Grapql_schema + it's easier to get an object with just an id. Combined primary keys would mean a lot of extra work for the resolvers to work.