Skip to content

NodeJS: Convergence on hiding IDs #4214

Closed

Description

@helderco

Overview

Related:

In the Nested queries feature, with every ID type argument, it was added the possibility to pass the object in instead of its ID:

-  withFile(path: string, source: FileID): Directory {
+  withFile(path: string, source: FileID | File): Directory {
...
-  file(id: FileID): File {
+  file(id: FileID | File): File {

Problem

However, the initial idea was to hide IDs altogether whenever possible. This nudges users in favor of the better DX (pass objects, don’t worry about ids), allows for laziness without the confusion of .id() calls not executing anything, and enables us more freedom to change how queries are stitched in the future.

Consistency

Both the Go SDK and Python SDK work the same way here, and I think the NodeJS SDK should be the same.

As a general rule, we want to replace any ID arguments with their corresponding object types, unless the argument name is id and the field’s return type is the same as the corresponding ID‘s object type 1. In that case, just leave the ID. It only happens in top-level fields (i.e., under Query).

-  withFile(path: string, source: FileID | File): Directory {
+  withFile(path: string, source: File): Directory {
...
-  file(id: FileID | File): File {
+  file(id: FileID): File {

See this for more on the outliers:

Credit to @grouville for noticing the inconsistency.

\cc @slumbering @dolanor

Footnotes

  1. It makes no sense to pass a File to Query.file() as it returns the same object we’re passing in. The point of these fields is to the get the object corresponding to an ID if you happen to have one for some reason. ↩

Activity

  1. dolanor commented on Jan 3, 2023

    @dolanor
    Contributor

    Does it mean we want to get rid of the union and only use objects EXCEPT for the case where the id is to get the object from the ID?.
    Or we keep the unions, but remove it when it doesn't make sense (passing a file to get a file (itself), instead of getting that file from its ID)?

    I'm personally ok to remove the union completely and use objects directly and use only ID to get the object.

  2. helderco commented on Jan 3, 2023

    @helderco
    ContributorAuthor

    Does it mean we want to get rid of the union and only use objects EXCEPT for the case where the id is to get the object from the ID?

    Yes.

    In python that exception is if the param has a field named id and the return value is the same as the corresponding type for that ID type.

    In Go the rule is just params named id only in fields under Query.

    In both cases the result is the same in the current API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions