Skip to content

Rename id argument name in fields that don’t return its type #4192

Closed

Description

@helderco

Some top-level fields return an object if you have their ID:

type Query {
    container(id: ContainerID, platform: Platform): Container!
    directory(id: DirectoryID): Directory!
    file(id: FileID!): File
    secret(id: SecretID!): Secret!    
    socket(id: SocketID): Socket!
}

There’s one exception to this “rule”. I think it makes sense for us to rename this parameter to make it more consistent:

type Container {
  "Initializes this container from this DirectoryID."
- withRootfs(id: DirectoryID!): Container!
+ withRootfs(directory: DirectoryID!): Container!
}

Notes

  • directory is consistent with withDirectory(path: String!, directory: DirectoryID!). withRootfs is similar just with path set to /;
  • Container.withFS doesn’t matter as it’s deprecated and is going to be removed;
  • Downside is the breaking change but for codegen clients, withRootfs‘s id being a required argument, the name is hidden from usage so it shouldn’t actually break most users;
  • This was surfaced in Python: Don’t accept an object for parameters named id (and the return is of the same type) #4191.

Activity

  1. added
    area/engine
    on Dec 13, 2022
  2. dolanor commented on Jan 5, 2023

    @dolanor
    Contributor

    I also found that some optional methods parameters are named id when passing the object makes more sense. We should rename them as well.

    example:

    export type ClientContainerOpts = {
    -  id?: ContainerID | Container
    +  id?: Container
       platform?: Platform
    }
  3. helderco commented on Jan 5, 2023

    @helderco
    ContributorAuthor

    @dolanor I'm pretty sure all those optional ids are meant to keep their ID. Have something been added in the meantime?

    Your ClientContainerOpts example comes from here:

    extend type Query {
      """
      Load a container from ID.
      Null ID returns an empty container (scratch).
      Optional platform argument initializes new containers to execute and publish as that platform. Platform defaults to that of the builder's host.
      """
      container(id: ContainerID, platform: Platform): Container!
    }

    So we do mean to pass an ID here, to get the corresponding Container object.

  4. gerhard commented on Jul 18, 2023

    @gerhard
    Contributor
  5. changed the title [-]Proposal: Rename `id` argument name in fields that don’t return its type[/-] [+]Rename `id` argument name in fields that don’t return its type[/+] on Jul 24, 2023
  6. added
    kind/breaking
    and removed on Jul 24, 2023
  7. self-assigned this
    on Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/enginekind/breaking

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions