jcward / haxe-graphql

Utilities for working with Haxe and GraphQL.
MIT License
23 stars 6 forks source link

GraphQL SDL unions genearte Haxe Enum in presence of __typename #44

Closed skilgoreT closed 9 months ago

skilgoreT commented 9 months ago

Unions that include the __typename intrinsic in the named operation generate Haxe enums and the as_enum() method on the abstract return type

  enum ContentModuleType
  {
    POLL
    TASKLIST
  }
  type TaskListModule {
    content_type: ContentModuleType!
    tasklist_id: ID!
  }
  type PollModule {
    content_type: ContentModuleType!
    poll_id: ID!
  }
  union ContentModule = PollModule | TaskListModule
  type Query
  {
    content_module_by_id(id: ID!): ContentModule!
  }
  query GetContentModuleById($$id: ID!) {
    content_module_by_id(id: $$id) {
      __typename
      ... on TaskListModule {
        content_type
        tasklist_id
      }
      ... on PollModule {
        content_type
        poll_id
      }
    }
  }

The above generates client code

image

jcward commented 9 months ago

Closed via squash merge: https://github.com/jcward/haxe-graphql/commit/16dd303f87ede7dfc6905ddf2fa892e595a3e620