Skip to content

Commit 2335d6e

Browse files
mattbretlbenjie
authored andcommitted
fix: remove sortable/filterable from functions with required args (#519)
1 parent 1a9dc17 commit 2335d6e

11 files changed

+69
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function getCompatibleComputedColumns(build, table) {
2121
const { pseudoColumnName } = computedColumnDetails;
2222

2323
// Must have only one required argument
24-
const nonOptionalArgumentsCount = proc.argDefaultsNum - proc.inputArgsCount;
24+
const nonOptionalArgumentsCount = proc.inputArgsCount - proc.argDefaultsNum;
2525
if (nonOptionalArgumentsCount > 1) {
2626
return memo;
2727
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export default (function PgOrderComputedColumnsPlugin(builder) {
4141

4242
// Must have only one required argument
4343
const nonOptionalArgumentsCount =
44-
proc.argDefaultsNum - proc.inputArgsCount;
44+
proc.inputArgsCount - proc.argDefaultsNum;
4545
if (nonOptionalArgumentsCount > 1) {
4646
return memo;
4747
}

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

+14
Original file line numberDiff line numberDiff line change
@@ -6213,6 +6213,8 @@ type Post implements Node {
62136213
offset: Int
62146214
): PostComputedIntervalSetConnection!
62156215
computedTextArray: [String]
6216+
computedWithOptionalArg(i: Int): Int
6217+
computedWithRequiredArg(i: Int!): Int
62166218
enums: [AnEnum]
62176219
headline: String!
62186220
headlineTrimmed(length: Int, omission: String): String
@@ -6323,6 +6325,9 @@ input PostCondition {
63236325
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
63246326
comptypes: [ComptypeInput]
63256327

6328+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
6329+
computedWithOptionalArg: Int
6330+
63266331
\\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\"
63276332
enums: [AnEnum]
63286333

@@ -6412,6 +6417,8 @@ enum PostsOrderBy {
64126417
BODY_DESC
64136418
COMPTYPES_ASC
64146419
COMPTYPES_DESC
6420+
COMPUTED_WITH_OPTIONAL_ARG_ASC
6421+
COMPUTED_WITH_OPTIONAL_ARG_DESC
64156422
ENUMS_ASC
64166423
ENUMS_DESC
64176424
HEADLINE_ASC
@@ -16192,6 +16199,8 @@ type Post implements Node {
1619216199
offset: Int
1619316200
): PostComputedIntervalSetConnection!
1619416201
computedTextArray: [String]
16202+
computedWithOptionalArg(i: Int): Int
16203+
computedWithRequiredArg(i: Int!): Int
1619516204
enums: [AnEnum]
1619616205
headline: String!
1619716206
headlineTrimmed(length: Int, omission: String): String
@@ -16302,6 +16311,9 @@ input PostCondition {
1630216311
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
1630316312
comptypes: [ComptypeInput]
1630416313

16314+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
16315+
computedWithOptionalArg: Int
16316+
1630516317
\\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\"
1630616318
enums: [AnEnum]
1630716319

@@ -16391,6 +16403,8 @@ enum PostsOrderBy {
1639116403
BODY_DESC
1639216404
COMPTYPES_ASC
1639316405
COMPTYPES_DESC
16406+
COMPUTED_WITH_OPTIONAL_ARG_ASC
16407+
COMPUTED_WITH_OPTIONAL_ARG_DESC
1639416408
ENUMS_ASC
1639516409
ENUMS_DESC
1639616410
HEADLINE_ASC

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

+7
Original file line numberDiff line numberDiff line change
@@ -6213,6 +6213,8 @@ type Post implements Node {
62136213
offset: Int
62146214
): PostComputedIntervalSetConnection!
62156215
computedTextArray: [String]
6216+
computedWithOptionalArg(i: Int): Int
6217+
computedWithRequiredArg(i: Int!): Int
62166218
enums: [AnEnum]
62176219
headline: String!
62186220
headlineTrimmed(length: Int, omission: String): String
@@ -6323,6 +6325,9 @@ input PostCondition {
63236325
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
63246326
comptypes: [ComptypeInput]
63256327
6328+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
6329+
computedWithOptionalArg: Int
6330+
63266331
\\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\"
63276332
enums: [AnEnum]
63286333
@@ -6412,6 +6417,8 @@ enum PostsOrderBy {
64126417
BODY_DESC
64136418
COMPTYPES_ASC
64146419
COMPTYPES_DESC
6420+
COMPUTED_WITH_OPTIONAL_ARG_ASC
6421+
COMPUTED_WITH_OPTIONAL_ARG_DESC
64156422
ENUMS_ASC
64166423
ENUMS_DESC
64176424
HEADLINE_ASC

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

+7
Original file line numberDiff line numberDiff line change
@@ -6458,6 +6458,8 @@ type Post implements Node {
64586458
offset: Int
64596459
): PostComputedIntervalSetConnection!
64606460
computedTextArray: [String]
6461+
computedWithOptionalArg(i: Int): Int
6462+
computedWithRequiredArg(i: Int!): Int
64616463
enums: [AnEnum]
64626464
headline: String!
64636465
headlineTrimmed(length: Int, omission: String): String
@@ -6562,6 +6564,9 @@ input PostCondition {
65626564
\\"\\"\\"Checks for equality with the object’s \`authorId\` field.\\"\\"\\"
65636565
authorId: Int
65646566
6567+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
6568+
computedWithOptionalArg: Int
6569+
65656570
\\"\\"\\"Checks for equality with the object’s \`id\` field.\\"\\"\\"
65666571
id: Int
65676572
}
@@ -6641,6 +6646,8 @@ type PostsEdge {
66416646
enum PostsOrderBy {
66426647
AUTHOR_ID_ASC
66436648
AUTHOR_ID_DESC
6649+
COMPUTED_WITH_OPTIONAL_ARG_ASC
6650+
COMPUTED_WITH_OPTIONAL_ARG_DESC
66446651
ID_ASC
66456652
ID_DESC
66466653
NATURAL

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

+7
Original file line numberDiff line numberDiff line change
@@ -6213,6 +6213,8 @@ type Post implements N {
62136213
offset: Int
62146214
): PostComputedIntervalSetConnection!
62156215
computedTextArray: [String]
6216+
computedWithOptionalArg(i: Int): Int
6217+
computedWithRequiredArg(i: Int!): Int
62166218
enums: [AnEnum]
62176219
headline: String!
62186220
headlineTrimmed(length: Int, omission: String): String
@@ -6323,6 +6325,9 @@ input PostCondition {
63236325
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
63246326
comptypes: [ComptypeInput]
63256327
6328+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
6329+
computedWithOptionalArg: Int
6330+
63266331
\\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\"
63276332
enums: [AnEnum]
63286333
@@ -6412,6 +6417,8 @@ enum PostsOrderBy {
64126417
BODY_DESC
64136418
COMPTYPES_ASC
64146419
COMPTYPES_DESC
6420+
COMPUTED_WITH_OPTIONAL_ARG_ASC
6421+
COMPUTED_WITH_OPTIONAL_ARG_DESC
64156422
ENUMS_ASC
64166423
ENUMS_DESC
64176424
HEADLINE_ASC

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

+7
Original file line numberDiff line numberDiff line change
@@ -2313,6 +2313,8 @@ type Post implements Node {
23132313
offset: Int
23142314
): PostComputedIntervalSetConnection!
23152315
computedTextArray: [String]
2316+
computedWithOptionalArg(i: Int): Int
2317+
computedWithRequiredArg(i: Int!): Int
23162318
enums: [AnEnum]
23172319
headlineTrimmed(length: Int, omission: String): String
23182320
headlineTrimmedNoDefaults(length: Int, omission: String): String
@@ -2358,6 +2360,9 @@ input PostCondition {
23582360
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
23592361
comptypes: [ComptypeInput]
23602362
2363+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
2364+
computedWithOptionalArg: Int
2365+
23612366
\\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\"
23622367
enums: [AnEnum]
23632368
@@ -2442,6 +2447,8 @@ enum PostsOrderBy {
24422447
BODY_DESC
24432448
COMPTYPES_ASC
24442449
COMPTYPES_DESC
2450+
COMPUTED_WITH_OPTIONAL_ARG_ASC
2451+
COMPUTED_WITH_OPTIONAL_ARG_DESC
24452452
ENUMS_ASC
24462453
ENUMS_DESC
24472454
ID_ASC

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

+7
Original file line numberDiff line numberDiff line change
@@ -7528,6 +7528,8 @@ type Post implements Node {
75287528
offset: Int
75297529
): PostComputedIntervalSetConnection!
75307530
computedTextArray: [String]
7531+
computedWithOptionalArg(i: Int): Int
7532+
computedWithRequiredArg(i: Int!): Int
75317533
enums: [AnEnum]
75327534
headline: String!
75337535
headlineTrimmed(length: Int, omission: String): String
@@ -7638,6 +7640,9 @@ input PostCondition {
76387640
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
76397641
comptypes: [ComptypeInput]
76407642

7643+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
7644+
computedWithOptionalArg: Int
7645+
76417646
\\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\"
76427647
enums: [AnEnum]
76437648

@@ -7727,6 +7732,8 @@ enum PostsOrderBy {
77277732
BODY_DESC
77287733
COMPTYPES_ASC
77297734
COMPTYPES_DESC
7735+
COMPUTED_WITH_OPTIONAL_ARG_ASC
7736+
COMPUTED_WITH_OPTIONAL_ARG_DESC
77307737
ENUMS_ASC
77317738
ENUMS_DESC
77327739
HEADLINE_ASC

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

+7
Original file line numberDiff line numberDiff line change
@@ -6256,6 +6256,8 @@ type Post implements Node {
62566256
after: Cursor
62576257
): PostComputedIntervalSetConnection!
62586258
computedTextArray: [String]
6259+
computedWithOptionalArg(i: Int): Int
6260+
computedWithRequiredArg(i: Int!): Int
62596261
headlineTrimmed(length: Int, omission: String): String
62606262
headlineTrimmedNoDefaults(length: Int, omission: String): String
62616263
headlineTrimmedStrict(length: Int, omission: String): String
@@ -6302,6 +6304,9 @@ input PostCondition {
63026304

63036305
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
63046306
comptypes: [ComptypeInput]
6307+
6308+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
6309+
computedWithOptionalArg: Int
63056310
}
63066311

63076312
\\"\\"\\"An input for mutations affecting \`Post\`\\"\\"\\"
@@ -6390,6 +6395,8 @@ enum PostsOrderBy {
63906395
ENUMS_DESC
63916396
COMPTYPES_ASC
63926397
COMPTYPES_DESC
6398+
COMPUTED_WITH_OPTIONAL_ARG_ASC
6399+
COMPUTED_WITH_OPTIONAL_ARG_DESC
63936400
PRIMARY_KEY_ASC
63946401
PRIMARY_KEY_DESC
63956402
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -5599,6 +5599,8 @@ type Post {
55995599
offset: Int
56005600
): PostComputedIntervalSetConnection!
56015601
computedTextArray: [String]
5602+
computedWithOptionalArg(i: Int): Int
5603+
computedWithRequiredArg(i: Int!): Int
56025604
enums: [AnEnum]
56035605
headline: String!
56045606
headlineTrimmed(length: Int, omission: String): String
@@ -5704,6 +5706,9 @@ input PostCondition {
57045706
\\"\\"\\"Checks for equality with the object’s \`comptypes\` field.\\"\\"\\"
57055707
comptypes: [ComptypeInput]
57065708

5709+
\\"\\"\\"Checks for equality with the object’s \`computedWithOptionalArg\` field.\\"\\"\\"
5710+
computedWithOptionalArg: Int
5711+
57075712
\\"\\"\\"Checks for equality with the object’s \`enums\` field.\\"\\"\\"
57085713
enums: [AnEnum]
57095714

@@ -5793,6 +5798,8 @@ enum PostsOrderBy {
57935798
BODY_DESC
57945799
COMPTYPES_ASC
57955800
COMPTYPES_DESC
5801+
COMPUTED_WITH_OPTIONAL_ARG_ASC
5802+
COMPUTED_WITH_OPTIONAL_ARG_DESC
57965803
ENUMS_ASC
57975804
ENUMS_DESC
57985805
HEADLINE_ASC

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

+4
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ create function a.post_computed_compound_type_array(post a.post, object c.compou
358358
create function a.post_computed_text_array(post a.post) returns text[] as $$ select ARRAY['str1','str2','str3']; $$ language sql stable;
359359
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;
360360
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;
361+
create function a.post_computed_with_required_arg(post a.post, i int) returns int as $$ select 1; $$ language sql stable strict;
362+
comment on function a.post_computed_with_required_arg(post a.post, i int) is E'@sortable\n@filterable';
363+
create function a.post_computed_with_optional_arg(post a.post, i int = 1) returns int as $$ select 1; $$ language sql stable strict;
364+
comment on function a.post_computed_with_optional_arg(post a.post, i int) is E'@sortable\n@filterable';
361365

362366
-- Procs -> custom mutations
363367
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;

0 commit comments

Comments
 (0)