-
Notifications
You must be signed in to change notification settings - Fork 841
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
concurrent-resolvers example is not correct #657
Comments
@chris-ramon Can you please take a look at this? |
i guess 'concurrent-resolvers' means resolve logic runs concurrently with the graphql schedule, and the schedule will wait and handle all promising resolve functions. Which Not means resolve func is run concurrently by the schedule, you should setup concurrently tasks by yourself |
here is my example: "concurrentFieldFoo": &graphql.Field{
Type: FieldFooType,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
var foo = Foo{Name: "Foo's name"}
fmt.Println("concurrentFieldFoo: sleeping for 5 secs...")
tick := time.NewTimer(time.Second * 5)
return func() (interface{}, error) {
<-tick.C
fmt.Println("concurrentFieldFoo: sleeping for 5 secs... done")
return &foo, nil
}, nil
},
},
"concurrentFieldBar": &graphql.Field{
Type: FieldBarType,
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
var bar = Bar{Name: "Bar's name"}
fmt.Println("concurrentFieldBar: sleeping for 5 secs...")
tick := time.NewTimer(time.Second * 5)
return func() (interface{}, error) {
<-tick.C
fmt.Println("concurrentFieldBar: sleeping for 5 secs... done")
return &bar, nil
}, nil
},
}, |
This is the conclusion I came to based on my experiments. :)
|
As per #592 if the resolver is made as a thunk, they will be concurrent. To confirm I took the example given at https://github.com/graphql-go/graphql/blob/master/examples/concurrent-resolvers/main.go and changed
QueryType
to thisconcurrentFieldFoo
andconcurrentFieldBar
have the same logic - deviating from the sample code where there was a go routine that was created to send the data in later - where both the resolvers sleep for 5 seconds.In my output, I was expecting to see, the following:
But I am seeing this:
This is not what I understood from #388 .
What am I missing here?
Full source attached here
The text was updated successfully, but these errors were encountered: