@@ -4,7 +4,7 @@ import { diff } from "@n1ru4l/json-patch-plus";
4
4
import { CombinedError } from "@urql/core" ;
5
5
import nock from "nock" ;
6
6
import { BackgroundActionHandle } from "../src/BackgroundActionHandle.js" ;
7
- import type { AnyModelManager , GadgetErrorGroup , LimitToKnownKeys } from "../src/index.js" ;
7
+ import type { AnyPublicModelManager , GadgetErrorGroup , LimitToKnownKeys } from "../src/index.js" ;
8
8
import {
9
9
GadgetConnection ,
10
10
actionRunner ,
@@ -48,6 +48,7 @@ describe("type checks", () => {
48
48
// eslint-disable-next-line jest/no-export
49
49
describe ( "operationRunners" , ( ) => {
50
50
let connection : GadgetConnection ;
51
+ let manager : AnyPublicModelManager ;
51
52
let query : string | undefined ;
52
53
let mockUrqlClient : MockUrqlClient ;
53
54
@@ -60,25 +61,26 @@ describe("operationRunners", () => {
60
61
} ,
61
62
} ) ;
62
63
jest . spyOn ( connection , "currentClient" as any , "get" ) . mockReturnValue ( mockUrqlClient as any ) ;
64
+ manager = { connection } as AnyPublicModelManager ;
63
65
} ) ;
64
66
65
67
describe ( "findOneRunner" , ( ) => {
66
68
test ( "can execute a findOne operation against a model" , async ( ) => {
67
69
const promise = findOneRunner ( { connection } , "widget" , "123" , { id : true , name : true } , "widget" ) ;
68
70
69
71
expect ( query ) . toMatchInlineSnapshot ( `
70
- "query widget($id: GadgetID!) {
71
- widget(id: $id) {
72
- id
73
- name
74
- __typename
75
- }
76
- gadgetMeta {
77
- hydrations(modelName:
78
- "widget")
79
- }
80
- }"
81
- ` ) ;
72
+ "query widget($id: GadgetID!) {
73
+ widget(id: $id) {
74
+ id
75
+ name
76
+ __typename
77
+ }
78
+ gadgetMeta {
79
+ hydrations(modelName:
80
+ "widget")
81
+ }
82
+ }"
83
+ ` ) ;
82
84
83
85
mockUrqlClient . executeQuery . pushResponse ( "widget" , {
84
86
data : {
@@ -316,32 +318,32 @@ describe("operationRunners", () => {
316
318
317
319
describe ( "findManyRunner" , ( ) => {
318
320
test ( "can execute a findMany operation against a model" , async ( ) => {
319
- const promise = findManyRunner ( { connection } as AnyModelManager , "widgets" , { id : true , name : true } , "widget" ) ;
321
+ const promise = findManyRunner ( { connection } as AnyPublicModelManager , "widgets" , { id : true , name : true } , "widget" ) ;
320
322
321
323
expect ( query ) . toMatchInlineSnapshot ( `
322
- "query widgets($after: String, $first: Int, $before: String, $last: Int) {
323
- widgets(after: $after, first: $first, before: $before, last: $last) {
324
- pageInfo {
325
- hasNextPage
326
- hasPreviousPage
327
- startCursor
328
- endCursor
329
- }
330
- edges {
331
- cursor
332
- node {
333
- id
334
- name
335
- __typename
336
- }
337
- }
338
- }
339
- gadgetMeta {
340
- hydrations(modelName:
341
- "widget")
342
- }
343
- }"
344
- ` ) ;
324
+ "query widgets($after: String, $first: Int, $before: String, $last: Int) {
325
+ widgets(after: $after, first: $first, before: $before, last: $last) {
326
+ pageInfo {
327
+ hasNextPage
328
+ hasPreviousPage
329
+ startCursor
330
+ endCursor
331
+ }
332
+ edges {
333
+ cursor
334
+ node {
335
+ id
336
+ name
337
+ __typename
338
+ }
339
+ }
340
+ }
341
+ gadgetMeta {
342
+ hydrations(modelName:
343
+ "widget")
344
+ }
345
+ }"
346
+ ` ) ;
345
347
346
348
mockUrqlClient . executeQuery . pushResponse ( "widgets" , {
347
349
data : {
@@ -369,7 +371,7 @@ describe("operationRunners", () => {
369
371
370
372
test ( "can execute a findMany operation against a namespaced model" , async ( ) => {
371
373
const promise = findManyRunner (
372
- { connection } as AnyModelManager ,
374
+ { connection } as AnyPublicModelManager ,
373
375
"widgets" ,
374
376
{ id : true , name : true } ,
375
377
"widget" ,
@@ -436,7 +438,7 @@ describe("operationRunners", () => {
436
438
437
439
test ( "can execute a findMany operation against a namespaced model when the namespace is a string" , async ( ) => {
438
440
const promise = findManyRunner (
439
- { connection } as AnyModelManager ,
441
+ { connection } as AnyPublicModelManager ,
440
442
"widgets" ,
441
443
{ id : true , name : true } ,
442
444
"widget" ,
@@ -502,9 +504,7 @@ describe("operationRunners", () => {
502
504
describe ( "actionRunner" , ( ) => {
503
505
test ( "can run a single create action" , async ( ) => {
504
506
const promise = actionRunner < { id : string ; name : string } > (
505
- {
506
- connection,
507
- } ,
507
+ manager ,
508
508
"createWidget" ,
509
509
{ id : true , name : true } ,
510
510
"widget" ,
@@ -544,9 +544,7 @@ describe("operationRunners", () => {
544
544
545
545
test ( "can run a single update action" , async ( ) => {
546
546
const promise = actionRunner < { id : string ; name : string } > (
547
- {
548
- connection,
549
- } ,
547
+ manager ,
550
548
"updateWidget" ,
551
549
{ id : true , name : true } ,
552
550
"widget" ,
@@ -591,9 +589,7 @@ describe("operationRunners", () => {
591
589
592
590
test ( "can run a single action with an object result type" , async ( ) => {
593
591
const promise = actionRunner (
594
- {
595
- connection,
596
- } ,
592
+ manager ,
597
593
"upsertWidget" ,
598
594
{ id : true , name : true , eventAt : true } ,
599
595
"widget" ,
@@ -646,9 +642,7 @@ describe("operationRunners", () => {
646
642
647
643
test ( "can run a single action with an object result type that has an inner return type" , async ( ) => {
648
644
const promise = actionRunner (
649
- {
650
- connection,
651
- } ,
645
+ manager ,
652
646
"upsertWidget" ,
653
647
{ id : true , name : true , eventAt : true } ,
654
648
"widget" ,
@@ -693,9 +687,7 @@ describe("operationRunners", () => {
693
687
694
688
test ( "can run an action with hasReturnType" , async ( ) => {
695
689
const promise = actionRunner (
696
- {
697
- connection,
698
- } ,
690
+ manager ,
699
691
"createWidget" ,
700
692
{ id : true , name : true } ,
701
693
"widget" ,
@@ -733,9 +725,7 @@ describe("operationRunners", () => {
733
725
734
726
test ( "can throw the error returned by the server for a single action" , async ( ) => {
735
727
const promise = actionRunner < { id : string ; name : string } > (
736
- {
737
- connection,
738
- } ,
728
+ manager ,
739
729
"updateWidget" ,
740
730
{ id : true , name : true } ,
741
731
"widget" ,
@@ -780,9 +770,7 @@ describe("operationRunners", () => {
780
770
781
771
test ( "can run a bulk action by ids" , async ( ) => {
782
772
const promise = actionRunner < { id : string ; name : string } > (
783
- {
784
- connection,
785
- } ,
773
+ manager ,
786
774
"bulkFlipWidgets" ,
787
775
{ id : true , name : true } ,
788
776
"widget" ,
@@ -830,9 +818,7 @@ describe("operationRunners", () => {
830
818
831
819
test ( "can run a bulk action with params" , async ( ) => {
832
820
const promise = actionRunner < { id : string ; name : string } > (
833
- {
834
- connection,
835
- } ,
821
+ manager ,
836
822
"bulkCreateWidgets" ,
837
823
{ id : true , name : true } ,
838
824
"widget" ,
@@ -880,9 +866,7 @@ describe("operationRunners", () => {
880
866
881
867
test ( "can run a bulk action with a returnType" , async ( ) => {
882
868
const promise = actionRunner (
883
- {
884
- connection,
885
- } ,
869
+ manager ,
886
870
"bulkCreateWidgets" ,
887
871
{ id : true , name : true } ,
888
872
"widget" ,
@@ -921,9 +905,7 @@ describe("operationRunners", () => {
921
905
922
906
test ( "can run a bulk action with an object returnType" , async ( ) => {
923
907
const promise = actionRunner (
924
- {
925
- connection,
926
- } ,
908
+ manager ,
927
909
"bulkUpsertWidgets" ,
928
910
{ id : true , name : true } ,
929
911
"widget" ,
@@ -970,9 +952,7 @@ describe("operationRunners", () => {
970
952
971
953
test ( "throws a nice error when a bulk action returns errors" , async ( ) => {
972
954
const promise = actionRunner < { id : string ; name : string } > (
973
- {
974
- connection,
975
- } ,
955
+ manager ,
976
956
"bulkCreateWidgets" ,
977
957
{ id : true , name : true } ,
978
958
"widget" ,
@@ -1010,9 +990,7 @@ describe("operationRunners", () => {
1010
990
1011
991
test ( "throws a nice error when a bulk action returns errors and data" , async ( ) => {
1012
992
const promise = actionRunner < { id : string ; name : string } > (
1013
- {
1014
- connection,
1015
- } ,
993
+ manager ,
1016
994
"bulkCreateWidgets" ,
1017
995
{ id : true , name : true } ,
1018
996
"widget" ,
@@ -1057,9 +1035,7 @@ describe("operationRunners", () => {
1057
1035
1058
1036
test ( "returns undefined when bulk action does not have a result" , async ( ) => {
1059
1037
const promise = actionRunner < { id : string ; name : string } > (
1060
- {
1061
- connection,
1062
- } ,
1038
+ manager ,
1063
1039
"bulkDeleteWidgets" ,
1064
1040
null ,
1065
1041
"widget" ,
@@ -1958,7 +1934,7 @@ describe("operationRunners", () => {
1958
1934
test ( "can run a live findMany" , async ( ) => {
1959
1935
const iterator = asyncIterableToIterator (
1960
1936
findManyRunner < { id : string ; name : string } , { live : true } > (
1961
- { connection } as AnyModelManager ,
1937
+ { connection } as AnyPublicModelManager ,
1962
1938
"widgets" ,
1963
1939
{ id : true , name : true } ,
1964
1940
"widget" ,
0 commit comments