Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(enum): enum views #704

Merged
merged 2 commits into from Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
388 changes: 200 additions & 188 deletions packages/graphile-build-pg/src/plugins/PgIntrospectionPlugin.js

Large diffs are not rendered by default.

Expand Up @@ -3,19 +3,22 @@ mutation {
letterDescription {
id
letter
letterViaView
}
}
createLetterDescription(
input: {
letterDescription: {
letter: C
letterViaView: C
description: "One does like to see the letter C"
}
}
) {
letterDescription {
id
letter
letterViaView
description
}
}
Expand Down
Expand Up @@ -3,25 +3,51 @@
nodes {
id
letter
letterViaView
description
}
}
reverse: allLetterDescriptions(orderBy: [LETTER_DESC]) {
nodes {
id
letter
letterViaView
description
}
}
reverseView: allLetterDescriptions(orderBy: [LETTER_VIA_VIEW_DESC]) {
nodes {
id
letter
letterViaView
description
}
}
b: letterDescriptionByLetter(letter: B) {
id
letter
letterViaView
description
}
bView: letterDescriptionByLetterViaView(letterViaView: B) {
id
letter
letterViaView
description
}
letterC: allLetterDescriptions(condition: { letter: C }) {
nodes {
id
letter
letterViaView
description
}
}
letterCView: allLetterDescriptions(condition: { letterViaView: C }) {
nodes {
id
letter
letterViaView
description
}
}
Expand Down
Expand Up @@ -68,12 +68,14 @@ Object {
"description": "One does like to see the letter C",
"id": 105,
"letter": "C",
"letterViaView": "C",
},
},
"deleteLetterDescriptionByLetter": Object {
"letterDescription": Object {
"id": 103,
"letter": "C",
"letterViaView": "C",
},
},
"referencingTableMutation": Object {
Expand Down
Expand Up @@ -1581,35 +1581,57 @@ Object {
"description": "The first letter in the alphabet",
"id": 101,
"letter": "A",
"letterViaView": "A",
},
Object {
"description": "Following closely behind the first letter, this is a popular choice",
"id": 102,
"letter": "B",
"letterViaView": "B",
},
Object {
"description": "Pronounced like 'sea'",
"id": 103,
"letter": "C",
"letterViaView": "C",
},
Object {
"description": "The first letter omitted from the 'ABC' phrase",
"id": 104,
"letter": "D",
"letterViaView": "D",
},
],
},
"b": Object {
"description": "Following closely behind the first letter, this is a popular choice",
"id": 102,
"letter": "B",
"letterViaView": "B",
},
"bView": Object {
"description": "Following closely behind the first letter, this is a popular choice",
"id": 102,
"letter": "B",
"letterViaView": "B",
},
"letterC": Object {
"nodes": Array [
Object {
"description": "Pronounced like 'sea'",
"id": 103,
"letter": "C",
"letterViaView": "C",
},
],
},
"letterCView": Object {
"nodes": Array [
Object {
"description": "Pronounced like 'sea'",
"id": 103,
"letter": "C",
"letterViaView": "C",
},
],
},
Expand All @@ -1619,21 +1641,53 @@ Object {
"description": "The first letter omitted from the 'ABC' phrase",
"id": 104,
"letter": "D",
"letterViaView": "D",
},
Object {
"description": "Pronounced like 'sea'",
"id": 103,
"letter": "C",
"letterViaView": "C",
},
Object {
"description": "Following closely behind the first letter, this is a popular choice",
"id": 102,
"letter": "B",
"letterViaView": "B",
},
Object {
"description": "The first letter in the alphabet",
"id": 101,
"letter": "A",
"letterViaView": "A",
},
],
},
"reverseView": Object {
"nodes": Array [
Object {
"description": "The first letter omitted from the 'ABC' phrase",
"id": 104,
"letter": "D",
"letterViaView": "D",
},
Object {
"description": "Pronounced like 'sea'",
"id": 103,
"letter": "C",
"letterViaView": "C",
},
Object {
"description": "Following closely behind the first letter, this is a popular choice",
"id": 102,
"letter": "B",
"letterViaView": "B",
},
Object {
"description": "The first letter in the alphabet",
"id": 101,
"letter": "A",
"letterViaView": "A",
},
],
},
Expand Down
Expand Up @@ -94,6 +94,16 @@ input DeleteLetterDescriptionByLetterInput {
letter: LetterAToD!
}

"""All input for the \`deleteLetterDescriptionByLetterViaView\` mutation."""
input DeleteLetterDescriptionByLetterViaViewInput {
"""
An arbitrary string value with no semantic meaning. Will be included in the
payload verbatim. May be used to track mutations by the client.
"""
clientMutationId: String
letterViaView: LetterAToDViaView!
}

"""All input for the \`deleteLetterDescription\` mutation."""
input DeleteLetterDescriptionInput {
"""
Expand Down Expand Up @@ -222,10 +232,25 @@ enum LetterAToD {
D
}

enum LetterAToDViaView {
"""The letter A"""
A

"""The letter B"""
B

"""The letter C"""
C

"""The letter D"""
D
}

type LetterDescription implements Node {
description: String
id: Int!
letter: LetterAToD!
letterViaView: LetterAToDViaView!

"""
A globally unique identifier. Can be used in various places throughout the system to identify this single value.
Expand All @@ -246,13 +271,17 @@ input LetterDescriptionCondition {

"""Checks for equality with the object’s \`letter\` field."""
letter: LetterAToD

"""Checks for equality with the object’s \`letterViaView\` field."""
letterViaView: LetterAToDViaView
}

"""An input for mutations affecting \`LetterDescription\`"""
input LetterDescriptionInput {
description: String
id: Int
letter: LetterAToD!
letterViaView: LetterAToDViaView!
}

"""
Expand All @@ -262,6 +291,7 @@ input LetterDescriptionPatch {
description: String
id: Int
letter: LetterAToD
letterViaView: LetterAToDViaView
}

"""A connection to a list of \`LetterDescription\` values."""
Expand Down Expand Up @@ -300,6 +330,8 @@ enum LetterDescriptionsOrderBy {
ID_DESC
LETTER_ASC
LETTER_DESC
LETTER_VIA_VIEW_ASC
LETTER_VIA_VIEW_DESC
NATURAL
PRIMARY_KEY_ASC
PRIMARY_KEY_DESC
Expand Down Expand Up @@ -363,6 +395,14 @@ type Mutation {
input: DeleteLetterDescriptionByLetterInput!
): DeleteLetterDescriptionPayload

"""Deletes a single \`LetterDescription\` using a unique key."""
deleteLetterDescriptionByLetterViaView(
"""
The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
"""
input: DeleteLetterDescriptionByLetterViaViewInput!
): DeleteLetterDescriptionPayload

"""Deletes a single \`ReferencingTable\` using its globally unique id."""
deleteReferencingTable(
"""
Expand Down Expand Up @@ -411,6 +451,14 @@ type Mutation {
input: UpdateLetterDescriptionByLetterInput!
): UpdateLetterDescriptionPayload

"""Updates a single \`LetterDescription\` using a unique key and a patch."""
updateLetterDescriptionByLetterViaView(
"""
The exclusive input argument for this mutation. An object type, make sure to see documentation for this object’s fields.
"""
input: UpdateLetterDescriptionByLetterViaViewInput!
): UpdateLetterDescriptionPayload

"""
Updates a single \`ReferencingTable\` using its globally unique id and a patch.
"""
Expand Down Expand Up @@ -522,6 +570,7 @@ type Query implements Node {
): LetterDescription
letterDescriptionById(id: Int!): LetterDescription
letterDescriptionByLetter(letter: LetterAToD!): LetterDescription
letterDescriptionByLetterViaView(letterViaView: LetterAToDViaView!): LetterDescription

"""Fetches an object given its globally unique \`ID\`."""
node(
Expand Down Expand Up @@ -696,6 +745,21 @@ input UpdateLetterDescriptionByLetterInput {
letterDescriptionPatch: LetterDescriptionPatch!
}

"""All input for the \`updateLetterDescriptionByLetterViaView\` mutation."""
input UpdateLetterDescriptionByLetterViaViewInput {
"""
An arbitrary string value with no semantic meaning. Will be included in the
payload verbatim. May be used to track mutations by the client.
"""
clientMutationId: String

"""
An object where the defined keys will be set on the \`LetterDescription\` being updated.
"""
letterDescriptionPatch: LetterDescriptionPatch!
letterViaView: LetterAToDViaView!
}

"""All input for the \`updateLetterDescription\` mutation."""
input UpdateLetterDescriptionInput {
"""
Expand Down
10 changes: 5 additions & 5 deletions packages/postgraphile-core/__tests__/kitchen-sink-data.sql
Expand Up @@ -276,11 +276,11 @@ insert into named_query_builder.toy_categories(toy_id, category_id, approved) va

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

alter sequence enum_tables.referencing_table_id_seq restart with 432;
insert into enum_tables.referencing_table(enum_1, enum_2, enum_3) values
Expand Down
6 changes: 6 additions & 0 deletions packages/postgraphile-core/__tests__/kitchen-sink-schema.sql
Expand Up @@ -1143,12 +1143,18 @@ create table enum_tables.abcd (letter text primary key, description text);
comment on column enum_tables.abcd.description is E'@enumDescription';
comment on table enum_tables.abcd is E'@enum\n@enumName LetterAToD';

create view enum_tables.abcd_view as (select * from enum_tables.abcd);
comment on view enum_tables.abcd_view is E'@primaryKey letter\n@enum\n@enumName LetterAToDViaView';

create table enum_tables.letter_descriptions(
id serial primary key,
letter text not null references enum_tables.abcd unique,
letter_via_view text not null unique,
description text
);

comment on table enum_tables.letter_descriptions is '@foreignKey (letter_via_view) references enum_tables.abcd_view';

create table enum_tables.lots_of_enums (
id serial primary key,
enum_1 text,
Expand Down