crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Improve pgSelectSingleFromRecord $record argument type

Open danzho opened this issue 1 year ago • 0 comments

Benjie asked me to file an issue for this on Discord: https://discord.com/channels/489127045289476126/1273438253017464852/1273762862531088488

There's full context there.

But the issue is that pgSelectSingleFromRecord could probably accept a broader type for its $record arg:

plans: {
  Query: {
    pendingEmailChangeRequest() {
      const $userId = context().get("user_id");
      const $record = loadOne($userId, loadEmailRecordByUserId);
      const $email = pgSelectSingleFromRecord(emails, ($record as any));
      return $email;
    },
  },
},

I suppose other types make sense too like an access step where I already have the record through other means than loadOne:

plans: {
  Query: {
    foo() {
      const $user = withPgClient(pgClient => { /* ... */ })
      return object({
        user: $user
      })
    }
  },
  FooPayload: {
    user($data) {
      const $record = $data.get('user') 
      const $user = pgSelectSingleFromRecord(users, $record as any)
      return $user
    }
  }
}

danzho avatar Aug 16 '24 22:08 danzho