-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver_test.go
36 lines (29 loc) · 876 Bytes
/
server_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package main
import (
"testing"
"example.com/subgraph-template-go-gqlgen-boilerplate/graph"
"example.com/subgraph-template-go-gqlgen-boilerplate/graph/generated"
"example.com/subgraph-template-go-gqlgen-boilerplate/graph/model"
"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/stretchr/testify/assert"
)
func TestFooQuery(t *testing.T) {
srv := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
client := client.New(srv)
fooQuery := `
query FooQuery {
foo(id: "1") {
id
name
}
}
`
var resp struct {
Foo *model.Foo
}
client.MustPost(fooQuery, &resp)
assert.NotNil(t, resp.Foo, "Foo should not be nil")
assert.Equal(t, "1", resp.Foo.ID, "Foo ID should be the same")
assert.Equal(t, "Name", *resp.Foo.Name, "Foo Name should be the same")
}