Last active
September 22, 2019 14:28
-
-
Save singingwolfboy/49a1f63345327280fa366a96ab929d98 to your computer and use it in GitHub Desktop.
I want to create a `@relationTargetColumn` smart comment, for making relationships that target only a single column in a table instead of an entire object. Ideally, other columns on the relationship should appear in the edge data. This is an example of what I want to create, but I'm not sure what's the best way to get started...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
drop schema if exists sh cascade; | |
create schema sh; | |
create table sh.hero ( | |
id serial primary key, | |
species text | |
); | |
create table sh.hero_name ( | |
id serial primary key, | |
hero_id int not null constraint hero_name_hero_id_fkey references sh.hero (id), | |
name text not null, | |
category text | |
); | |
comment on constraint hero_name_hero_id_fkey on sh.hero_name is | |
E'@foreignFieldName names\n@relationTargetColumn name'; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert into sh.hero (id, species) values | |
(1, 'Kryptonian'), | |
(2, 'Amazonian'), | |
(3, 'Human'); | |
insert into sh.hero_name (id, hero_id, name, category) values | |
(1, 1, 'Superman', 'Hero'), | |
(2, 1, 'The Man of Steel', 'Title'), | |
(3, 1, 'Clark Kent', 'Civilian'), | |
(4, 2, 'Wonder Woman', 'Hero'), | |
(5, 2, 'Princess Diana of Themyscira', 'Amazonian'), | |
(6, 2, 'Diana Prince', 'Civilian'), | |
(7, 3, 'Batman', 'Hero'), | |
(8, 3, 'The Dark Knight', 'Title'), | |
(9, 3, 'Bruce Wayne', 'Civilian'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
allHeroes { | |
nodes { | |
species | |
names { | |
edges { | |
category | |
node { | |
name | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment