-
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
typechecking loop error with circular node reference #258
Comments
Looks like "field thunks" are the way to do this. The Using field thunks along with moving the definition into an var SomeType graphql.Type
func init() {
SomeType = graphql.NewObject(graphql.ObjectConfig{
Name: "SomeType",
Fields: func() graphql.Fields { // notice func here
return graphql.Fields{
"circularRef": {
Type: Environment,
},
}
},
})
} Update: I may have spoken too soon, I'm now getting a runtime error:
|
Ok, the issue is because a type-switch is being used to identify whether a thunk is being used, and my closure was not statically typed as var SomeType graphql.Type
func init() {
SomeType = graphql.NewObject(graphql.ObjectConfig{
Name: "SomeType",
Fields: graphql.FieldsThunk(func() graphql.Fields { // notice func here
return graphql.Fields{
"circularRef": {
Type: Environment,
},
}
}),
})
} |
You're a lifesaver, mate! Thank you. Closing the issue as this solution resolved it. |
As a side note, another way to do this is with |
there is a problem with FieldThunk and AddFieldConfig, if your object's fields returned by FieldThunk, you can't dynamically add field into your object by AddFieldConfig. I ran into this problem because I restruct my project's fields/types/schema module. |
I'm hitting a wall while trying to build an API with circular references between types.
A simplified example of my types looks like this:
Attempting to create this results in a
typechecking loop
error from the go compiler.This seems to be a result of the
employeeType
referencingroleType
which in turn referencesemployeeType
again.I would expect these kinds of models to be central to a Graph API. Is there a better way to be building this?
Thanks for any feedback.
The text was updated successfully, but these errors were encountered: