Skip to content

Union type mapping limitation #139

@visualage

Description

@visualage

We ran into a situation, which causes the union type resolution to fail. Here is a brief example.

public abstract class Item {
  /// some abstract property getters
}

public class AnotherItem {
}

public class ImmutableItem extends Item {
  /// actual implementation
}

public class Container {
}

public class ContainerResolver implements GraphQLResolver<Container> {
  public Item getItem(Container container) {
    // returns an ImmutableItem instance
  }

  public Object getUnion(Container container) {
    // returns an ImmutableItem instance or an AnotherItem instance
  }
}

Corresponding GraphQL schema:

type Item {
   ...
}

type AnotherItem {
   ...
}

union ItemUnion = Item | AnotherItem

type Container {
  item: Item
  union: ItemUnion
}

With the example above, when the union returns an ImmutableItem instance, we always get an error saying ImmutableItem is not a valid type, even if we manually register GraphQL type Item as class ImmutableItem. It appears to me that the resolver would automatically resolve the GraphQL type Item into class Item because the returned type in ContainerResolver, and it cannot register two classes for one GraphQL type (one would overwrite the other).

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