diff --git a/packages/graphile-build-pg/src/plugins/PgConditionComputedColumnPlugin.js b/packages/graphile-build-pg/src/plugins/PgConditionComputedColumnPlugin.js index 8bdd1259e..968195ca7 100644 --- a/packages/graphile-build-pg/src/plugins/PgConditionComputedColumnPlugin.js +++ b/packages/graphile-build-pg/src/plugins/PgConditionComputedColumnPlugin.js @@ -21,7 +21,7 @@ function getCompatibleComputedColumns(build, table) { const { pseudoColumnName } = computedColumnDetails; // Must have only one required argument - const nonOptionalArgumentsCount = proc.argDefaultsNum - proc.inputArgsCount; + const nonOptionalArgumentsCount = proc.inputArgsCount - proc.argDefaultsNum; if (nonOptionalArgumentsCount > 1) { return memo; } diff --git a/packages/graphile-build-pg/src/plugins/PgOrderComputedColumnsPlugin.js b/packages/graphile-build-pg/src/plugins/PgOrderComputedColumnsPlugin.js index 7ba59ea0f..36bdb6cc8 100644 --- a/packages/graphile-build-pg/src/plugins/PgOrderComputedColumnsPlugin.js +++ b/packages/graphile-build-pg/src/plugins/PgOrderComputedColumnsPlugin.js @@ -41,7 +41,7 @@ export default (function PgOrderComputedColumnsPlugin(builder) { // Must have only one required argument const nonOptionalArgumentsCount = - proc.argDefaultsNum - proc.inputArgsCount; + proc.inputArgsCount - proc.argDefaultsNum; if (nonOptionalArgumentsCount > 1) { return memo; } diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/defaultOptions.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/defaultOptions.test.js.snap index 527322695..044f3ea4c 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/defaultOptions.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/defaultOptions.test.js.snap @@ -6213,6 +6213,8 @@ type Post implements Node { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headline: String! headlineTrimmed(length: Int, omission: String): String @@ -6323,6 +6325,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\" enums: [AnEnum] @@ -6412,6 +6417,8 @@ enum PostsOrderBy { BODY_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ENUMS_ASC ENUMS_DESC HEADLINE_ASC @@ -16192,6 +16199,8 @@ type Post implements Node { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headline: String! headlineTrimmed(length: Int, omission: String): String @@ -16302,6 +16311,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\" enums: [AnEnum] @@ -16391,6 +16403,8 @@ enum PostsOrderBy { BODY_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ENUMS_ASC ENUMS_DESC HEADLINE_ASC diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/function-clash.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/function-clash.test.js.snap index c54f63aa0..116788e75 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/function-clash.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/function-clash.test.js.snap @@ -6213,6 +6213,8 @@ type Post implements Node { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headline: String! headlineTrimmed(length: Int, omission: String): String @@ -6323,6 +6325,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\" enums: [AnEnum] @@ -6412,6 +6417,8 @@ enum PostsOrderBy { BODY_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ENUMS_ASC ENUMS_DESC HEADLINE_ASC diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/indexes.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/indexes.test.js.snap index 8101a20dc..953835bd0 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/indexes.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/indexes.test.js.snap @@ -6458,6 +6458,8 @@ type Post implements Node { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headline: String! headlineTrimmed(length: Int, omission: String): String @@ -6562,6 +6564,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`authorId\` field.\\"\\"\\" authorId: Int + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`id\` field.\\"\\"\\" id: Int } @@ -6641,6 +6646,8 @@ type PostsEdge { enum PostsOrderBy { AUTHOR_ID_ASC AUTHOR_ID_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ID_ASC ID_DESC NATURAL diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/inflect-core.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/inflect-core.test.js.snap index 4d4a9c6d4..b8ce2f81f 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/inflect-core.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/inflect-core.test.js.snap @@ -6213,6 +6213,8 @@ type Post implements N { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headline: String! headlineTrimmed(length: Int, omission: String): String @@ -6323,6 +6325,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\" enums: [AnEnum] @@ -6412,6 +6417,8 @@ enum PostsOrderBy { BODY_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ENUMS_ASC ENUMS_DESC HEADLINE_ASC diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap index 506dee42c..6f20ea1fa 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/pgColumnFilter.test.js.snap @@ -2313,6 +2313,8 @@ type Post implements Node { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headlineTrimmed(length: Int, omission: String): String headlineTrimmedNoDefaults(length: Int, omission: String): String @@ -2358,6 +2360,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\" enums: [AnEnum] @@ -2442,6 +2447,8 @@ enum PostsOrderBy { BODY_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ENUMS_ASC ENUMS_DESC ID_ASC diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/rbac.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/rbac.test.js.snap index 2bc08baac..a4c682935 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/rbac.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/rbac.test.js.snap @@ -7528,6 +7528,8 @@ type Post implements Node { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headline: String! headlineTrimmed(length: Int, omission: String): String @@ -7638,6 +7640,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\" enums: [AnEnum] @@ -7727,6 +7732,8 @@ enum PostsOrderBy { BODY_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ENUMS_ASC ENUMS_DESC HEADLINE_ASC diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simplePrint.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simplePrint.test.js.snap index e1ff92f93..dc7af1924 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simplePrint.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/simplePrint.test.js.snap @@ -6256,6 +6256,8 @@ type Post implements Node { after: Cursor ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int headlineTrimmed(length: Int, omission: String): String headlineTrimmedNoDefaults(length: Int, omission: String): String headlineTrimmedStrict(length: Int, omission: String): String @@ -6302,6 +6304,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int } \\"\\"\\"An input for mutations affecting \`Post\`\\"\\"\\" @@ -6390,6 +6395,8 @@ enum PostsOrderBy { ENUMS_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC PRIMARY_KEY_ASC PRIMARY_KEY_DESC } diff --git a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/skipNodePlugin.test.js.snap b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/skipNodePlugin.test.js.snap index 8e1ea7808..906693e04 100644 --- a/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/skipNodePlugin.test.js.snap +++ b/packages/postgraphile-core/__tests__/integration/schema/__snapshots__/skipNodePlugin.test.js.snap @@ -5599,6 +5599,8 @@ type Post { offset: Int ): PostComputedIntervalSetConnection! computedTextArray: [String] + computedWithOptionalArg(i: Int): Int + computedWithRequiredArg(i: Int!): Int enums: [AnEnum] headline: String! headlineTrimmed(length: Int, omission: String): String @@ -5704,6 +5706,9 @@ input PostCondition { \\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\" comptypes: [ComptypeInput] + \\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\" + computedWithOptionalArg: Int + \\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\" enums: [AnEnum] @@ -5793,6 +5798,8 @@ enum PostsOrderBy { BODY_DESC COMPTYPES_ASC COMPTYPES_DESC + COMPUTED_WITH_OPTIONAL_ARG_ASC + COMPUTED_WITH_OPTIONAL_ARG_DESC ENUMS_ASC ENUMS_DESC HEADLINE_ASC diff --git a/packages/postgraphile-core/__tests__/kitchen-sink-schema.sql b/packages/postgraphile-core/__tests__/kitchen-sink-schema.sql index 3df6fea5a..ea8dbc817 100644 --- a/packages/postgraphile-core/__tests__/kitchen-sink-schema.sql +++ b/packages/postgraphile-core/__tests__/kitchen-sink-schema.sql @@ -358,6 +358,10 @@ create function a.post_computed_compound_type_array(post a.post, object c.compou create function a.post_computed_text_array(post a.post) returns text[] as $$ select ARRAY['str1','str2','str3']; $$ language sql stable; create function a.post_computed_interval_array(post a.post) returns interval[] as $$ select ARRAY[interval '12 seconds', interval '3 hours', interval '34567 seconds']; $$ language sql stable; create function a.post_computed_interval_set(post a.post) returns setof interval as $$ begin return next interval '12 seconds'; return next interval '3 hours'; return next interval '34567 seconds'; end; $$ language plpgsql stable; +create function a.post_computed_with_required_arg(post a.post, i int) returns int as $$ select 1; $$ language sql stable strict; +comment on function a.post_computed_with_required_arg(post a.post, i int) is E'@sortable\n@filterable'; +create function a.post_computed_with_optional_arg(post a.post, i int = 1) returns int as $$ select 1; $$ language sql stable strict; +comment on function a.post_computed_with_optional_arg(post a.post, i int) is E'@sortable\n@filterable'; -- Procs -> custom mutations create function a.mutation_compound_type_array(object c.compound_type) returns c.compound_type[] as $$ select ARRAY[object, (null, null, null, null, null, null, null, null)::c.compound_type, (object.a + 1, object.b, object.c, object.d, object.e, object.f, object.g, object.foo_bar)::c.compound_type]; $$ language sql volatile;