Skip to content

Commit

Permalink
Add descriptions and entities
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Aug 17, 2024
1 parent e78cf85 commit 520bf42
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 31 deletions.
36 changes: 29 additions & 7 deletions graphile-build/graphile-build-pg/src/plugins/PgAttributesPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,35 @@ export const PgAttributesPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
"-condition:attribute:filterBy": {},
"-attribute:select": {},
"-attribute:base": {},
"-attribute:insert": {},
"-attribute:update": {},
"-attribute:filterBy": {},
"-attribute:orderBy": {},
"-attribute:select": {
description: "can this attribute be selected?",
entities: ["pgCodecAttribute"],
},
"-attribute:insert": {
description: "can this attribute be written on create?",
entities: ["pgCodecAttribute"],
},
"-attribute:update": {
description: "can this attribute be updated?",
entities: ["pgCodecAttribute"],
},
"-attribute:base": {
description: "should we add this attribute to the 'base' input type?",
entities: ["pgCodecAttribute"],
},
"-attribute:filterBy": {
description: "can we filter by this attribute?",
entities: ["pgCodecAttribute"],
},
"-condition:attribute:filterBy": {
description:
"can we filter by this attribute in the `condition` argument?",
entities: ["pgCodecAttribute"],
},
"-attribute:orderBy": {
description: "can we order by this attribute?",
entities: ["pgCodecAttribute"],
},
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ export const PgConditionArgumentPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
filter: {},
filter: {
description: "can we filter this resource/codec",
entities: ["pgCodec", "pgResource"],
},
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ export const PgConditionCustomFieldsPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
"proc:filterBy": {},
"proc:filterBy": {
description:
"can we filter by the result of this proc (function resource)",
entities: ["pgResource"],
},
},
},
entityBehavior: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export const PgConnectionTotalCountPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
totalCount: {},
totalCount: {
description: "on a codec, should we add the totalCount field?",
entities: ["pgCodec"],
},
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,9 +345,19 @@ export const PgCustomTypeFieldPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
queryField: {},
mutationField: {},
typeField: {},
queryField: {
description: 'a "custom query function"',
entities: ["pgResource"],
},
mutationField: {
description: 'a "custom mutation function"',
entities: ["pgResource"],
},
typeField: {
description:
'a "custom field function" - add it to a specific type (aka "computed column")',
entities: ["pgResource"],
},
},
},
entityBehavior: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@ export const PgMutationCreatePlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
"insert:resource:select": {},
"insert:resource:select": {
description:
"can select the row that was inserted (on the mutation payload)",
entities: ["pgResource"],
},
record: {
description: "record type used for insert",
entities: ["pgResource"],
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,28 @@ export const PgMutationUpdateDeletePlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
"constraint:resource:update": {},
"constraint:resource:delete": {},
"update:resource:select": {},
"delete:resource:nodeId": {},
"delete:resource:select": {},
"constraint:resource:update": {
description: "can update a record by this constraint",
entities: ["pgResourceUnique"],
},
"constraint:resource:delete": {
description: "can delete a record by this constraint",
entities: ["pgResourceUnique"],
},
"delete:resource:nodeId": {
description: "can delete a record by its Node ID",
entities: ["pgResource"],
},
"update:resource:select": {
description:
"can you select the record that was updated on the mutation payload?",
entities: ["pgResource"],
},
"delete:resource:select": {
description:
"can you select the record that was deleted on the mutation payload?",
entities: ["pgResource"],
},
},
},
entityBehavior: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ declare global {
interface BehaviorStrings {
"nodeId:insert": true;
"nodeId:update": true;
"nodeId:delete": true;
"nodeId:base": true;
"nodeId:filterBy": true;
}
Expand Down Expand Up @@ -64,11 +63,26 @@ export const PgNodeIdAttributesPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
"nodeId:insert": {},
"nodeId:update": {},
"nodeId:delete": {},
"nodeId:base": {},
"nodeId:filterBy": {},
"nodeId:insert": {
description:
"can we insert to the columns represented by this nodeId which represents a table related via foreign key constraint?",
entities: ["pgCodecRelation"],
},
"nodeId:update": {
description:
"can we update the columns represented by this nodeId which represents a table related via foreign key constraint?",
entities: ["pgCodecRelation"],
},
"nodeId:base": {
description:
'should we add a nodeId input representing this foreign key constraint to the "base" input type?',
entities: ["pgCodecRelation"],
},
"nodeId:filterBy": {
description:
"can we filter by the columns represented by this nodeId which represents a table related via foreign key constraint?",
entities: ["pgCodecRelation"],
},
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,11 @@ export const PgProceduresPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
"resource:connection:backwards": {},
"resource:connection:backwards": {
description:
"can we paginate backwards through this collection's connection?",
entities: ["pgResource"],
},
},
},

Expand Down
18 changes: 16 additions & 2 deletions graphile-build/graphile-build-pg/src/plugins/PgRelationsPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const ref_sql = te.ref(sql, "sql");
declare global {
namespace GraphileBuild {
interface BehaviorStrings {
"singularRelation:resource:single": true;
"singularRelation:resource:list": true;
"singularRelation:resource:connection": true;
}
Expand Down Expand Up @@ -509,8 +510,21 @@ export const PgRelationsPlugin: GraphileConfig.Plugin = {
schema: {
behaviorRegistry: {
add: {
"singularRelation:resource:list": {},
"singularRelation:resource:connection": {},
"singularRelation:resource:single": {
description:
"can we get a single one of these (resource) from a type?",
entities: ["pgCodecRelation", "pgCodecRef"],
},
"singularRelation:resource:list": {
description:
"should we add a list field to navigate this singular relationship (when we know there can be at most one)?",
entities: ["pgCodecRelation", "pgCodecRef"],
},
"singularRelation:resource:connection": {
description:
"should we add a connection field to navigate this singular relationship (when we know there can be at most one)?",
entities: ["pgCodecRelation", "pgCodecRef"],
},
},
},
entityBehavior: {
Expand Down
4 changes: 3 additions & 1 deletion graphile-build/graphile-build/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ interface RegisterObjectType {
declare global {
namespace GraphileBuild {
type BehaviorString =
| (string & { __incomingBehaviorString: true })
| (string & {
/* lies; just for TS */ readonly __incomingBehaviorString: unique symbol;
})
| `${"" | "-"}${keyof GraphileBuild.BehaviorStrings}`;

/**
Expand Down
4 changes: 2 additions & 2 deletions graphile-build/graphile-build/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -860,8 +860,8 @@ declare global {
Record<
keyof GraphileBuild.BehaviorStrings,
{
description?: string;
entities?: (keyof GraphileBuild.BehaviorEntities)[];
description: string;
entities: (keyof GraphileBuild.BehaviorEntities)[];
}
>
>;
Expand Down

0 comments on commit 520bf42

Please sign in to comment.