-
Notifications
You must be signed in to change notification settings - Fork 839
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
Circular references causes compiler error #164
Comments
@rubberviscous I also had this problem once. My solution was dynamically adding one of the problematic fields inside package main
import (
"github.com/graphql-go/graphql"
)
var showType = graphql.NewObject(graphql.ObjectConfig{
Name: "Show",
Fields: graphql.Fields{
"id": &graphql.Field{Type: graphql.String},
"episodes": &graphql.Field{Type: graphql.NewList(episodeType)},
},
})
var episodeType = graphql.NewObject(graphql.ObjectConfig{
Name: "Episode",
Fields: graphql.Fields{
"id": &graphql.Field{Type: graphql.String},
},
})
func init() {
episodeType.AddFieldConfig("show", &graphql.Field{Type: showType})
} |
@sfriedel That worked! Many thanks! |
Hi @rubberviscous, thanks a lot for reaching us for a question, also the solution @sfriedel wrote above is the go-to one, closing this one, thanks guys! |
I have the same issue here, but for InputObject. I tried the same workaround, but there is no AddFieldConfig defined for InputObject. I've done the following hack but I'm worried about it being broken in a subsequent commit:
Any other suggestions? |
When defining GraphQL types where two types reference each other, this causes compiler error when building:
typechecking loop involving showType = graphql.NewObject(graphql.ObjectConfig literal)
Here's the GraphQL types that I have defined where it references each other:
var showType = graphql.NewObject( graphql.ObjectConfig{ Name: "Show", Fields: graphql.Fields{ "id": &graphql.Field{ Type: graphql.String, }, "episodes": &graphql.Field{ Type: graphql.NewList(episodeType), } } } )
var episodeType = graphql.NewObject( graphql.ObjectConfig{ Name: "Episode", Fields: graphql.Fields{ "id": &graphql.Field{ Type: graphql.String, }, "show": &graphql.Field{ Type: showType, } } )
Are there any workarounds for this issue?
The text was updated successfully, but these errors were encountered: