Skip to content

Switch with associated data instead of constructor methods for partials #1260

@ermik

Description

@ermik

This is a feature request.

Current implementation

Given a Node interface type and A, B, and C types that conform to it, it the following schema:

interface Node {
    id: ID!
}

type A implements Node {
    id: ID!
    name: String
}

# ... etc

type Query {
    node: Node
}

the code generator for the following query

query NodeQuery {
    node {
        id
        ... on A {
             name
        }
    }
}

would generate code that has asA getter producing an optional of A swift type.

This means for N types, we have to write N if let valueA = data.node.asA clauses.

Proposal

Generate an enum for Node type that has all of the type's known implementors as cases.

enum Node {
    case A(data: StructA)
    case B(data: StructB)
    // etc...
}

which would allow for a simpler access of the interface values using a switch, while still allowing if ... else syntax using if case let.

Metadata

Metadata

Assignees

No one assigned

    Labels

    codegenIssues related to or arising from code generationenhancementIssues outlining new things we want to do or things that will make our lives as devs easierv1.x

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions