Repository navigation
Description
Overview
Related:
- Consider hiding the need for IDs in codegen clients #3558
- Go SDK: Pass objects by reference instead of ID #3598
- Node.js SDK: Nested queries #3996
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
-
It makes no sense to pass a
FiletoQuery.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
dolanor commentedon Jan 3, 2023
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.
helderco commentedon Jan 3, 2023
Yes.
In python that exception is if the param has a field named
idand the return value is the same as the corresponding type for that ID type.In Go the rule is just params named
idonly in fields underQuery.In both cases the result is the same in the current API.