Skip to content

Commit d2770a5

Browse files
authored
feat(enum): enum views (#704)
1 parent 0ef3e6b commit d2770a5

File tree

8 files changed

+360
-193
lines changed

8 files changed

+360
-193
lines changed

packages/graphile-build-pg/src/plugins/PgIntrospectionPlugin.js

Lines changed: 200 additions & 188 deletions
Large diffs are not rendered by default.

packages/postgraphile-core/__tests__/fixtures/mutations/enum_tables.mutations.graphql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,22 @@ mutation {
33
letterDescription {
44
id
55
letter
6+
letterViaView
67
}
78
}
89
createLetterDescription(
910
input: {
1011
letterDescription: {
1112
letter: C
13+
letterViaView: C
1214
description: "One does like to see the letter C"
1315
}
1416
}
1517
) {
1618
letterDescription {
1719
id
1820
letter
21+
letterViaView
1922
description
2023
}
2124
}

packages/postgraphile-core/__tests__/fixtures/queries/enum_tables.queries.graphql

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,51 @@
33
nodes {
44
id
55
letter
6+
letterViaView
67
description
78
}
89
}
910
reverse: allLetterDescriptions(orderBy: [LETTER_DESC]) {
1011
nodes {
1112
id
1213
letter
14+
letterViaView
15+
description
16+
}
17+
}
18+
reverseView: allLetterDescriptions(orderBy: [LETTER_VIA_VIEW_DESC]) {
19+
nodes {
20+
id
21+
letter
22+
letterViaView
1323
description
1424
}
1525
}
1626
b: letterDescriptionByLetter(letter: B) {
1727
id
1828
letter
29+
letterViaView
30+
description
31+
}
32+
bView: letterDescriptionByLetterViaView(letterViaView: B) {
33+
id
34+
letter
35+
letterViaView
1936
description
2037
}
2138
letterC: allLetterDescriptions(condition: { letter: C }) {
2239
nodes {
2340
id
2441
letter
42+
letterViaView
43+
description
44+
}
45+
}
46+
letterCView: allLetterDescriptions(condition: { letterViaView: C }) {
47+
nodes {
48+
id
49+
letter
50+
letterViaView
2551
description
2652
}
2753
}

packages/postgraphile-core/__tests__/integration/__snapshots__/mutations.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ Object {
6868
"description": "One does like to see the letter C",
6969
"id": 105,
7070
"letter": "C",
71+
"letterViaView": "C",
7172
},
7273
},
7374
"deleteLetterDescriptionByLetter": Object {
7475
"letterDescription": Object {
7576
"id": 103,
7677
"letter": "C",
78+
"letterViaView": "C",
7779
},
7880
},
7981
"referencingTableMutation": Object {

packages/postgraphile-core/__tests__/integration/__snapshots__/queries.test.js.snap

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,35 +1581,57 @@ Object {
15811581
"description": "The first letter in the alphabet",
15821582
"id": 101,
15831583
"letter": "A",
1584+
"letterViaView": "A",
15841585
},
15851586
Object {
15861587
"description": "Following closely behind the first letter, this is a popular choice",
15871588
"id": 102,
15881589
"letter": "B",
1590+
"letterViaView": "B",
15891591
},
15901592
Object {
15911593
"description": "Pronounced like 'sea'",
15921594
"id": 103,
15931595
"letter": "C",
1596+
"letterViaView": "C",
15941597
},
15951598
Object {
15961599
"description": "The first letter omitted from the 'ABC' phrase",
15971600
"id": 104,
15981601
"letter": "D",
1602+
"letterViaView": "D",
15991603
},
16001604
],
16011605
},
16021606
"b": Object {
16031607
"description": "Following closely behind the first letter, this is a popular choice",
16041608
"id": 102,
16051609
"letter": "B",
1610+
"letterViaView": "B",
1611+
},
1612+
"bView": Object {
1613+
"description": "Following closely behind the first letter, this is a popular choice",
1614+
"id": 102,
1615+
"letter": "B",
1616+
"letterViaView": "B",
16061617
},
16071618
"letterC": Object {
16081619
"nodes": Array [
16091620
Object {
16101621
"description": "Pronounced like 'sea'",
16111622
"id": 103,
16121623
"letter": "C",
1624+
"letterViaView": "C",
1625+
},
1626+
],
1627+
},
1628+
"letterCView": Object {
1629+
"nodes": Array [
1630+
Object {
1631+
"description": "Pronounced like 'sea'",
1632+
"id": 103,
1633+
"letter": "C",
1634+
"letterViaView": "C",
16131635
},
16141636
],
16151637
},
@@ -1619,21 +1641,53 @@ Object {
16191641
"description": "The first letter omitted from the 'ABC' phrase",
16201642
"id": 104,
16211643
"letter": "D",
1644+
"letterViaView": "D",
1645+
},
1646+
Object {
1647+
"description": "Pronounced like 'sea'",
1648+
"id": 103,
1649+
"letter": "C",
1650+
"letterViaView": "C",
1651+
},
1652+
Object {
1653+
"description": "Following closely behind the first letter, this is a popular choice",
1654+
"id": 102,
1655+
"letter": "B",
1656+
"letterViaView": "B",
1657+
},
1658+
Object {
1659+
"description": "The first letter in the alphabet",
1660+
"id": 101,
1661+
"letter": "A",
1662+
"letterViaView": "A",
1663+
},
1664+
],
1665+
},
1666+
"reverseView": Object {
1667+
"nodes": Array [
1668+
Object {
1669+
"description": "The first letter omitted from the 'ABC' phrase",
1670+
"id": 104,
1671+
"letter": "D",
1672+
"letterViaView": "D",
16221673
},
16231674
Object {
16241675
"description": "Pronounced like 'sea'",
16251676
"id": 103,
16261677
"letter": "C",
1678+
"letterViaView": "C",
16271679
},
16281680
Object {
16291681
"description": "Following closely behind the first letter, this is a popular choice",
16301682
"id": 102,
16311683
"letter": "B",
1684+
"letterViaView": "B",
16321685
},
16331686
Object {
16341687
"description": "The first letter in the alphabet",
16351688
"id": 101,
16361689
"letter": "A",
1690+
"letterViaView": "A",
16371691
},
16381692
],
16391693
},

packages/postgraphile-core/__tests__/integration/schema/__snapshots__/enum_tables.test.js.snap

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ input DeleteLetterDescriptionByLetterInput {
9494
letter: LetterAToD!
9595
}
9696
97+
"""All input for the \`deleteLetterDescriptionByLetterViaView\` mutation."""
98+
input DeleteLetterDescriptionByLetterViaViewInput {
99+
"""
100+
An arbitrary string value with no semantic meaning. Will be included in the
101+
payload verbatim. May be used to track mutations by the client.
102+
"""
103+
clientMutationId: String
104+
letterViaView: LetterAToDViaView!
105+
}
106+
97107
"""All input for the \`deleteLetterDescription\` mutation."""
98108
input DeleteLetterDescriptionInput {
99109
"""
@@ -222,10 +232,25 @@ enum LetterAToD {
222232
D
223233
}
224234
235+
enum LetterAToDViaView {
236+
"""The letter A"""
237+
A
238+
239+
"""The letter B"""
240+
B
241+
242+
"""The letter C"""
243+
C
244+
245+
"""The letter D"""
246+
D
247+
}
248+
225249
type LetterDescription implements Node {
226250
description: String
227251
id: Int!
228252
letter: LetterAToD!
253+
letterViaView: LetterAToDViaView!
229254
230255
"""
231256
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
@@ -246,13 +271,17 @@ input LetterDescriptionCondition {
246271
247272
"""Checks for equality with the object’s \`letter\` field."""
248273
letter: LetterAToD
274+
275+
"""Checks for equality with the object’s \`letterViaView\` field."""
276+
letterViaView: LetterAToDViaView
249277
}
250278
251279
"""An input for mutations affecting \`LetterDescription\`"""
252280
input LetterDescriptionInput {
253281
description: String
254282
id: Int
255283
letter: LetterAToD!
284+
letterViaView: LetterAToDViaView!
256285
}
257286
258287
"""
@@ -262,6 +291,7 @@ input LetterDescriptionPatch {
262291
description: String
263292
id: Int
264293
letter: LetterAToD
294+
letterViaView: LetterAToDViaView
265295
}
266296
267297
"""A connection to a list of \`LetterDescription\` values."""
@@ -300,6 +330,8 @@ enum LetterDescriptionsOrderBy {
300330
ID_DESC
301331
LETTER_ASC
302332
LETTER_DESC
333+
LETTER_VIA_VIEW_ASC
334+
LETTER_VIA_VIEW_DESC
303335
NATURAL
304336
PRIMARY_KEY_ASC
305337
PRIMARY_KEY_DESC
@@ -363,6 +395,14 @@ type Mutation {
363395
input: DeleteLetterDescriptionByLetterInput!
364396
): DeleteLetterDescriptionPayload
365397
398+
"""Deletes a single \`LetterDescription\` using a unique key."""
399+
deleteLetterDescriptionByLetterViaView(
400+
"""
401+
The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
402+
"""
403+
input: DeleteLetterDescriptionByLetterViaViewInput!
404+
): DeleteLetterDescriptionPayload
405+
366406
"""Deletes a single \`ReferencingTable\` using its globally unique id."""
367407
deleteReferencingTable(
368408
"""
@@ -411,6 +451,14 @@ type Mutation {
411451
input: UpdateLetterDescriptionByLetterInput!
412452
): UpdateLetterDescriptionPayload
413453
454+
"""Updates a single \`LetterDescription\` using a unique key and a patch."""
455+
updateLetterDescriptionByLetterViaView(
456+
"""
457+
The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
458+
"""
459+
input: UpdateLetterDescriptionByLetterViaViewInput!
460+
): UpdateLetterDescriptionPayload
461+
414462
"""
415463
Updates a single \`ReferencingTable\` using its globally unique id and a patch.
416464
"""
@@ -522,6 +570,7 @@ type Query implements Node {
522570
): LetterDescription
523571
letterDescriptionById(id: Int!): LetterDescription
524572
letterDescriptionByLetter(letter: LetterAToD!): LetterDescription
573+
letterDescriptionByLetterViaView(letterViaView: LetterAToDViaView!): LetterDescription
525574
526575
"""Fetches an object given its globally unique \`ID\`."""
527576
node(
@@ -696,6 +745,21 @@ input UpdateLetterDescriptionByLetterInput {
696745
letterDescriptionPatch: LetterDescriptionPatch!
697746
}
698747
748+
"""All input for the \`updateLetterDescriptionByLetterViaView\` mutation."""
749+
input UpdateLetterDescriptionByLetterViaViewInput {
750+
"""
751+
An arbitrary string value with no semantic meaning. Will be included in the
752+
payload verbatim. May be used to track mutations by the client.
753+
"""
754+
clientMutationId: String
755+
756+
"""
757+
An object where the defined keys will be set on the \`LetterDescription\` being updated.
758+
"""
759+
letterDescriptionPatch: LetterDescriptionPatch!
760+
letterViaView: LetterAToDViaView!
761+
}
762+
699763
"""All input for the \`updateLetterDescription\` mutation."""
700764
input UpdateLetterDescriptionInput {
701765
"""

packages/postgraphile-core/__tests__/kitchen-sink-data.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,11 @@ insert into named_query_builder.toy_categories(toy_id, category_id, approved) va
276276

277277
--------------------------------------------------------------------------------
278278
alter sequence enum_tables.letter_descriptions_id_seq restart with 101;
279-
insert into enum_tables.letter_descriptions(letter, description) values
280-
('A', 'The first letter in the alphabet'),
281-
('B', 'Following closely behind the first letter, this is a popular choice'),
282-
('C', 'Pronounced like ''sea'''),
283-
('D', 'The first letter omitted from the ''ABC'' phrase');
279+
insert into enum_tables.letter_descriptions(letter, letter_via_view, description) values
280+
('A', 'A', 'The first letter in the alphabet'),
281+
('B', 'B', 'Following closely behind the first letter, this is a popular choice'),
282+
('C', 'C', 'Pronounced like ''sea'''),
283+
('D', 'D', 'The first letter omitted from the ''ABC'' phrase');
284284

285285
alter sequence enum_tables.referencing_table_id_seq restart with 432;
286286
insert into enum_tables.referencing_table(enum_1, enum_2, enum_3) values

packages/postgraphile-core/__tests__/kitchen-sink-schema.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,12 +1143,18 @@ create table enum_tables.abcd (letter text primary key, description text);
11431143
comment on column enum_tables.abcd.description is E'@enumDescription';
11441144
comment on table enum_tables.abcd is E'@enum\n@enumName LetterAToD';
11451145

1146+
create view enum_tables.abcd_view as (select * from enum_tables.abcd);
1147+
comment on view enum_tables.abcd_view is E'@primaryKey letter\n@enum\n@enumName LetterAToDViaView';
1148+
11461149
create table enum_tables.letter_descriptions(
11471150
id serial primary key,
11481151
letter text not null references enum_tables.abcd unique,
1152+
letter_via_view text not null unique,
11491153
description text
11501154
);
11511155

1156+
comment on table enum_tables.letter_descriptions is '@foreignKey (letter_via_view) references enum_tables.abcd_view';
1157+
11521158
create table enum_tables.lots_of_enums (
11531159
id serial primary key,
11541160
enum_1 text,

0 commit comments

Comments
 (0)