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 · 2 comments

Comments

Projects
None yet
1 participant
@stephen
Copy link
Member

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

This comment has been minimized.

Copy link
Member Author

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

This comment has been minimized.

Copy link
Member Author

stephen commented Jul 21, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.