I am experimenting with converting an API to GraphQL, and I have a database that has many-to-many relationships that are stored via link tables; something like this:
CREATE TABLE accounts
(
id int,
last_name varchar,
first_name varchar
);
CREATE TABLE files
(
id int,
content varchar,
name varchar
);
CREATE TABLE account_file_links
(
id int,
account_id varchar,
file_id varchar,
can_edit tinyint,
FOREIGN KEY (account_id) REFERENCES accounts(id)
FOREIGN KEY (file_id) REFERENCES files(id)
);
I am wondering if I should be exposing these links as they're own types in the GraphQL schema or not. When I think of my database as a graph, the nodes are the accounts
and the reports
, while the edges would be the account_file_links
. There are attributes present on the link (in this example, the can_edit
property) that need to be presented to the API consumers.
editable_file
andregular_file
or something like that.