Skip to content

Named UnionTypes #760

Description

@michael-georgiadis

Description

Hey everyone, I am migrating a codebase from pure webonyx to your library. I am trying to keep the schemas 1-to-1 to avoid breaking changes. I think I am covered on everything with your awesome, except one thing. I haven't figured out the way to name the union types 😅 .

As I understand you build them on the fly by figuring out the PHP return type

Is there a way to actually name the union tho?

Activity

  1. andrew-demb commented on Sep 16, 2025

    @andrew-demb
    Contributor

    AFAIK, there's no way to configure a name for concrete unions, but you can inject your own naming strategy [1] in the GraphQL schema factory [2]. In your strategy, you can do whatever you want in getUnionTypeName method implementation [3].

    But it can be considered as a valid feature request - be able to hint union type name in the codebase with attributes.

    [1] \TheCodingMachine\GraphQLite\NamingStrategyInterface
    [2] \TheCodingMachine\GraphQLite\SchemaFactory::setNamingStrategy
    [3] \TheCodingMachine\GraphQLite\NamingStrategyInterface::getUnionTypeName

  2. oojacoboo commented on Sep 16, 2025

    @oojacoboo
    Collaborator

    Yea, there isn't a way to do this at the moment. Seems more fitting as an interface to me though, if you have a concrete name for a thing, instead of the union of two things. I guess a union alias is just shortcut of sorts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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