Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support GraphQL Interfaces / Union Types #78

Open
stephen opened this issue Feb 5, 2018 · 4 comments
Open

Support GraphQL Interfaces / Union Types #78

stephen opened this issue Feb 5, 2018 · 4 comments

Comments

@stephen
Copy link
Contributor

@stephen stephen commented Feb 5, 2018

Some ideas:

interfaces

  • golang interfaces, with some annotation for SDL/field funcs

union types

  • one-hot struct
@stephen stephen changed the title Support GraphQL Interfaces Support GraphQL Interfaces / Union Types Feb 12, 2018
@stephen
Copy link
Contributor Author

@stephen stephen commented Jul 21, 2018

union types

Add a special embed tag for unions that hints to the schemabuilder that this is a one-hot struct.

type GatewayUnion struct {
  *graphql.Union

  // Each must be anonymous, must be pointer type
  *models.Gateway
  *models.Vehicle
}

object.FieldFunc("gateways", func(...) ([]*GatewayUnion, error) {
  ags := models.AssetGateway.Fetch(ctx)
  if err != nil {
    return nil, err 
  }
  vgs := models.VehicleGateway.Fetch(ctx)
  if err != nil {
    return nil, err 
  }
  
  results := make([]*GatewayUnion, 0, len(ags)+len(vgs))
  for _, ag := range ags {
    results = append(results, &GatewayUnion{AssetGateway: ag})
  }

  for _, vg := range vgs {
    results = append(results, &GatewayUnion{VehicleGateway: vg})
  }
  return results, nil
})

Fields that return a union should be expected to only ever return one of the hot values. It will panic if that fails.

proposal

schemabuilder:

  • Add reflect for graphql.Union embedded types
  • In extracting union return types during resolution, verify one-hotness.

executor:

  • add support for union type in big switch, use On field on Fragment

introspection:

  • add support
@stephen
Copy link
Contributor Author

@stephen stephen commented Jul 21, 2018

@magiconair
Copy link

@magiconair magiconair commented Mar 18, 2021

Hi, we have been looking at this project and find its approach quite interesting. We needed support for interfaces and added this in a fork. Would you be interested in a PR?

@carwyn
Copy link

@carwyn carwyn commented Jul 5, 2021

@magiconair is this fork with interface support public and/or has there been a pull request for it into thunder yet?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants