Open aneeskA opened 2 years ago
@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. :)
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
As per https://github.com/graphql-go/graphql/issues/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 https://github.com/graphql-go/graphql/pull/388 .
What am I missing here?
Full source attached here