From 2043369c562b8920a7cfbcf2289f309e1f89fa1a Mon Sep 17 00:00:00 2001 From: MarioSimou Date: Thu, 9 May 2024 13:36:35 +0300 Subject: [PATCH 1/3] chore: update docs for pgSelectSingle.record() --- .../grafast/step-library/dataplan-pg/pgSelect.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md b/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md index 6400e1d763..f4965df2dd 100644 --- a/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md +++ b/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md @@ -349,7 +349,15 @@ Returns a `pgSelect` representing the records related via the ### $pgSelectSingle.record() -Returns a PgClassExpressionStep representing the entire table, useful for debugging or to use with `pgSelectSingleFromRecord`. +Returns a PgClassExpressionStep representing the entire table, useful for debugging or to use with `pgSelectSingleFromRecord`. Here is a simple example: + +```ts +const $user = usersResource.find({ id: constant(1) }); +const $record = $user.record(); + +sideEffect($record, (user) => console.dir(user)); +return $user; +``` ### $pgSelectSingle.cursor() From cacd3ee7b8aa337c5a30d1ceec83713fda7a365c Mon Sep 17 00:00:00 2001 From: Benjie Date: Thu, 9 May 2024 12:24:48 +0100 Subject: [PATCH 2/3] Apply suggestions from code review --- .../grafast/step-library/dataplan-pg/pgSelect.md | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md b/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md index f4965df2dd..d0f167ce3d 100644 --- a/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md +++ b/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md @@ -349,13 +349,19 @@ Returns a `pgSelect` representing the records related via the ### $pgSelectSingle.record() -Returns a PgClassExpressionStep representing the entire table, useful for debugging or to use with `pgSelectSingleFromRecord`. Here is a simple example: +Returns a PgClassExpressionStep representing the entire table, useful for debugging or to use with `pgSelectSingleFromRecord`. + +Here's a debugging example, we log out the full record to make sure it's the one we wanted: ```ts -const $user = usersResource.find({ id: constant(1) }); -const $record = $user.record(); +// Get the record from somewhere, e.g.: +const $user = usersResource.get({ id: constant(1) }); +// Get the full user object as a record and log it for debugging: +const $record = $user.record(); sideEffect($record, (user) => console.dir(user)); + +// Return the original $user object return $user; ``` From a4d9884452fb79090e4b10e9309cf935b90904fd Mon Sep 17 00:00:00 2001 From: Benjie Date: Thu, 9 May 2024 12:27:17 +0100 Subject: [PATCH 3/3] Apply an alternative change --- .../step-library/dataplan-pg/pgSelect.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md b/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md index d0f167ce3d..91fc10debf 100644 --- a/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md +++ b/grafast/website/grafast/step-library/dataplan-pg/pgSelect.md @@ -354,15 +354,19 @@ Returns a PgClassExpressionStep representing the entire table, useful for debugg Here's a debugging example, we log out the full record to make sure it's the one we wanted: ```ts -// Get the record from somewhere, e.g.: -const $user = usersResource.get({ id: constant(1) }); +const plans = { + Query: { + getUserById(_, { $id }) { + const $user = usersResource.get({ id: $id }); -// Get the full user object as a record and log it for debugging: -const $record = $user.record(); -sideEffect($record, (user) => console.dir(user)); + // Get the full user object as a record and log it for debugging: + const $record = $user.record(); + sideEffect($record, (user) => console.dir(user)); -// Return the original $user object -return $user; + return $user; + }, + }, +}; ``` ### $pgSelectSingle.cursor()