Skip to content

Commit 030bf23

Browse files
authored
Rename withPgClient to sideEffectWithPgClient (#2691)
2 parents 7a520cf + fbb575c commit 030bf23

17 files changed

Lines changed: 818 additions & 65 deletions

File tree

.changeset/giant-bags-press.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"grafast": patch
3+
---
4+
5+
Export Thunk type

.changeset/real-crabs-enter.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"postgraphile": patch
3+
"@dataplan/pg": patch
4+
---
5+
6+
Deprecate `withPgClient`/`withPgClientTransaction` because people are using them
7+
incorrectly and causing themselves N+1 issues. Instead, rename to
8+
`sideEffectWithPgClient` and introduce new `loadOneWithPgClient` and
9+
`loadManyWithPgClient` helpers that people should use instead of `withPgClient`.

grafast/dataplan-pg/__tests__/mutations/withPgClient/multipleActions.deopt.mermaid

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ graph TD
1010
subgraph "Buckets for mutations/withPgClient/multipleActions"
1111
Bucket0("Bucket 0 (root)"):::bucket
1212
Bucket1("Bucket 1 (mutationField)<br />Deps: 12, 15"):::bucket
13-
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 9<br /><br />ROOT WithPgClient{1}[9]"):::bucket
13+
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 9<br /><br />ROOT SideEffectWithPgClient{1}[9]"):::bucket
1414
Bucket3("Bucket 3 (listItem)<br /><br />ROOT __Item{3}ᐸ9ᐳ[13]"):::bucket
1515
end
1616
Bucket0 --> Bucket1
@@ -25,16 +25,16 @@ graph TD
2525
__Value2["__Value[2∈0] ➊<br />ᐸcontextᐳ"]:::plan
2626
__Value2 --> Access10
2727
__Value2 --> Access11
28-
WithPgClient9[["WithPgClient[9∈1] ➊<br />More deps:<br />- Constantᐸ§{ a: 3 }ᐳ[15]"]]:::sideeffectplan
29-
Object12 --> WithPgClient9
28+
SideEffectWithPgClient9[["SideEffectWithPgClient[9∈1] ➊<br />More deps:<br />- Constantᐸ§{ a: 3 }ᐳ[15]"]]:::sideeffectplan
29+
Object12 --> SideEffectWithPgClient9
3030
__Item13[/"__Item[13∈3]<br />ᐸ9ᐳ"\]:::itemplan
31-
WithPgClient9 ==> __Item13
31+
SideEffectWithPgClient9 ==> __Item13
3232

3333
%% define steps
3434
classDef bucket0 stroke:#696969
3535
class Bucket0,__Value2,Access10,Access11,Object12 bucket0
3636
classDef bucket1 stroke:#00bfff
37-
class Bucket1,WithPgClient9 bucket1
37+
class Bucket1,SideEffectWithPgClient9 bucket1
3838
classDef bucket2 stroke:#7f007f
3939
class Bucket2 bucket2
4040
classDef bucket3 stroke:#ffa500

grafast/dataplan-pg/__tests__/mutations/withPgClient/multipleActions.mermaid

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ graph TD
1010
subgraph "Buckets for mutations/withPgClient/multipleActions"
1111
Bucket0("Bucket 0 (root)"):::bucket
1212
Bucket1("Bucket 1 (mutationField)<br />Deps: 12, 15"):::bucket
13-
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 9<br /><br />ROOT WithPgClient{1}[9]"):::bucket
13+
Bucket2("Bucket 2 (nullableBoundary)<br />Deps: 9<br /><br />ROOT SideEffectWithPgClient{1}[9]"):::bucket
1414
Bucket3("Bucket 3 (listItem)<br /><br />ROOT __Item{3}ᐸ9ᐳ[13]"):::bucket
1515
end
1616
Bucket0 --> Bucket1
@@ -25,16 +25,16 @@ graph TD
2525
__Value2["__Value[2∈0] ➊<br />ᐸcontextᐳ"]:::plan
2626
__Value2 --> Access10
2727
__Value2 --> Access11
28-
WithPgClient9[["WithPgClient[9∈1] ➊<br />More deps:<br />- Constantᐸ§{ a: 3 }ᐳ[15]"]]:::sideeffectplan
29-
Object12 --> WithPgClient9
28+
SideEffectWithPgClient9[["SideEffectWithPgClient[9∈1] ➊<br />More deps:<br />- Constantᐸ§{ a: 3 }ᐳ[15]"]]:::sideeffectplan
29+
Object12 --> SideEffectWithPgClient9
3030
__Item13[/"__Item[13∈3]<br />ᐸ9ᐳ"\]:::itemplan
31-
WithPgClient9 ==> __Item13
31+
SideEffectWithPgClient9 ==> __Item13
3232

3333
%% define steps
3434
classDef bucket0 stroke:#696969
3535
class Bucket0,__Value2,Access10,Access11,Object12 bucket0
3636
classDef bucket1 stroke:#00bfff
37-
class Bucket1,WithPgClient9 bucket1
37+
class Bucket1,SideEffectWithPgClient9 bucket1
3838
classDef bucket2 stroke:#7f007f
3939
class Bucket2 bucket2
4040
classDef bucket3 stroke:#ffa500

grafast/dataplan-pg/src/examples/exampleSchema.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ import type {
122122
} from "../steps/pgUnionAll.js";
123123
import { pgUnionAll } from "../steps/pgUnionAll.js";
124124
import {
125-
WithPgClientStep,
126-
withPgClientTransaction,
125+
SideEffectWithPgClientStep,
126+
sideEffectWithPgClientTransaction,
127127
} from "../steps/withPgClient.js";
128128
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
129129

@@ -4951,23 +4951,24 @@ export function makeExampleSchema(
49514951
},
49524952
});
49534953

4954-
const MultipleActionsPayload = newObjectTypeBuilder<WithPgClientStep>(
4955-
WithPgClientStep,
4956-
)({
4957-
name: "MultipleActionsPayload",
4958-
fields: {
4959-
i: {
4960-
type: new GraphQLList(new GraphQLNonNull(GraphQLInt)),
4961-
plan: EXPORTABLE(
4962-
() =>
4963-
function plan($parent) {
4964-
return $parent;
4965-
},
4966-
[],
4967-
),
4954+
const MultipleActionsPayload =
4955+
newObjectTypeBuilder<SideEffectWithPgClientStep>(
4956+
SideEffectWithPgClientStep,
4957+
)({
4958+
name: "MultipleActionsPayload",
4959+
fields: {
4960+
i: {
4961+
type: new GraphQLList(new GraphQLNonNull(GraphQLInt)),
4962+
plan: EXPORTABLE(
4963+
() =>
4964+
function plan($parent) {
4965+
return $parent;
4966+
},
4967+
[],
4968+
),
4969+
},
49684970
},
4969-
},
4970-
});
4971+
});
49714972

49724973
const Mutation = newObjectTypeBuilder<__ValueStep<BaseGraphQLRootValue>>(
49734974
__ValueStep,
@@ -5186,9 +5187,9 @@ export function makeExampleSchema(
51865187
},
51875188
type: MultipleActionsPayload,
51885189
plan: EXPORTABLE(
5189-
(executor, object, sleep, sql, withPgClientTransaction) =>
5190+
(executor, object, sideEffectWithPgClientTransaction, sleep, sql) =>
51905191
function plan(_$root, { $input: { $a } }) {
5191-
const $transactionResult = withPgClientTransaction<
5192+
const $transactionResult = sideEffectWithPgClientTransaction<
51925193
{ a: number | null | undefined },
51935194
number[]
51945195
>(
@@ -5237,7 +5238,7 @@ export function makeExampleSchema(
52375238

52385239
return $transactionResult;
52395240
},
5240-
[executor, object, sleep, sql, withPgClientTransaction],
5241+
[executor, object, sideEffectWithPgClientTransaction, sleep, sql],
52415242
),
52425243
},
52435244
},

grafast/dataplan-pg/src/index.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,13 @@ import {
190190
} from "./steps/pgValidateParsedCursor.js";
191191
import { toPg, ToPgStep } from "./steps/toPg.js";
192192
import {
193+
loadManyWithPgClient,
194+
loadOneWithPgClient,
195+
sideEffectWithPgClient,
196+
SideEffectWithPgClientStep,
197+
SideEffectWithPgClientStepCallback,
198+
sideEffectWithPgClientTransaction,
193199
withPgClient,
194-
WithPgClientStep,
195-
WithPgClientStepCallback,
196200
withPgClientTransaction,
197201
} from "./steps/withPgClient.js";
198202
import { assertPgClassSingleStep } from "./utils.js";
@@ -217,6 +221,8 @@ export {
217221
isEnumCodec,
218222
KeysOfType,
219223
listOfCodec,
224+
loadManyWithPgClient,
225+
loadOneWithPgClient,
220226
makePgResourceOptions,
221227
MakePgServiceOptions,
222228
makeRegistry,
@@ -350,6 +356,10 @@ export {
350356
PlanByUniques,
351357
rangeOfCodec,
352358
recordCodec,
359+
sideEffectWithPgClient,
360+
SideEffectWithPgClientStep,
361+
SideEffectWithPgClientStepCallback,
362+
sideEffectWithPgClientTransaction,
353363
sqlFromArgDigests,
354364
sqlValueWithCodec,
355365
toPg,
@@ -359,8 +369,6 @@ export {
359369
WithPgClient,
360370
withPgClient,
361371
withPgClientFromPgService,
362-
WithPgClientStep,
363-
WithPgClientStepCallback,
364372
withPgClientTransaction,
365373
withSuperuserPgClientFromPgService,
366374
};
@@ -417,9 +425,11 @@ exportAsMany("@dataplan/pg", {
417425
PgTempTable,
418426
toPg,
419427
ToPgStep,
420-
withPgClient,
421-
withPgClientTransaction,
422-
WithPgClientStep,
428+
loadOneWithPgClient,
429+
loadManyWithPgClient,
430+
sideEffectWithPgClient,
431+
sideEffectWithPgClientTransaction,
432+
SideEffectWithPgClientStep,
423433
getWithPgClientFromPgService,
424434
withPgClientFromPgService,
425435
withSuperuserPgClientFromPgService,

0 commit comments

Comments
 (0)