Skip to content

can't use typereference as possibleType in uniontype #382

@jauco

Description

@jauco

A uniontype accepts only ObjectTypes as argument for possibleType. Not a TypeReference.

        newUnionType()
          .possibleType(newObject().build()) //Works
          .possibleType(new GraphQLTypeReference("SomeOtherType")) //doesn't work!
          .build();

Is this on purpose? Is there a workaround to allow two objects to reference each other in fields with a union type? i.e. How can I make the code below work?

GraphQLObjectType extraObject = newObject()
  .name("extraObject")
  .field(newFieldDefinition()
    .name("some field")
    .type(Scalars.GraphQLString)
  ).build();

GraphQLObjectType objA = newObject()
  .name("objA")
  .field(newFieldDefinition()
    .name("some field")
    .type(newUnionType()
      .possibleType(extraObject)
      .possibleType(new GraphQLTypeReference("objB")) //doesn't work
    )
  ).build();
GraphQLObjectType objB = newObject()
  .name("objB")
  .field(newFieldDefinition()
    .name("some field")
    .type(newUnionType()
      .possibleType(extraObject)
      .possibleType(objA)
    )
  ).build();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions