Closed danny-xx closed 1 year ago
Which version of the library are you using? I haven't cut a new release yet. These will be available in version v1.6.0
. I'm waiting for one more issue with directives to be resolved and I'm going to cut a release. Check this unit test for example:
https://github.com/graph-gophers/graphql-go/blob/master/graphql_test.go#L5200-L5353
You need to be on the master
branch to make it work now.
Thanks for the quick reply @pavelnikolov!
I'm using version v1.4.0
- is there an issue with this version?
I was using v1.0.0
before and didn't run into this issue.
The provided change is in the latest master
branch and it will be available in version v1.6.0
. I expect to release that in the next week or two. There are a few remaining things left before this version can be released. I just tested with these file and it works:
go.mod
:
module github.com/pavelnikolov/myapp
go 1.20
require github.com/graph-gophers/graphql-go v1.5.1-0.20230216224648-5aa631d05992
main.go
:
package main
import (
"context"
"encoding/json"
"os"
"github.com/graph-gophers/graphql-go"
)
type RootResolver struct{}
type QueryResolver struct{}
type MutationResolver1 struct{}
func (r *RootResolver) Query() *QueryResolver {
return &QueryResolver{}
}
func (r *RootResolver) Mutation() *MutationResolver1 {
return &MutationResolver1{}
}
func (*QueryResolver) Hello() string {
return "Hello query!"
}
func (*MutationResolver1) Hello() string {
return "Hello mutation!"
}
func main() {
sdl := `
schema {
query: Query
mutation: Mutation
}
type Query {
hello: String!
}
type Mutation {
hello: String!
}
`
schema := graphql.MustParseSchema(sdl, &RootResolver{})
reqs := []string{
`query { hello }`,
`mutation { hello }`,
}
for _, r := range reqs {
res := schema.Exec(context.Background(), r, "", nil)
enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", " ")
err := enc.Encode(res)
if err != nil {
panic(err)
}
}
}
This is my result:
$ go run main.go
{
"data": {
"hello": "Hello query!"
}
}
{
"data": {
"hello": "Hello mutation!"
}
}
thanks for the confirmation! I'll try it again once v1.6.0
is released
Hi folks! I'm having some trouble getting the "separate resolvers for different operations" to work. I followed the example code in README but got this error message:
here's my handler code:
Everything works fine on the query resolver (no root resolver). I'm wondering if I did something wrong on the code above. Thanks in advance if anyone could take a look!