-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
mutation_with_custom_scalar_test.go
51 lines (44 loc) · 1.43 KB
/
mutation_with_custom_scalar_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package followschema
import (
"context"
"testing"
"github.com/stretchr/testify/require"
"github.com/99designs/gqlgen/client"
"github.com/99designs/gqlgen/graphql/handler"
)
func TestErrorInsideMutationArgument(t *testing.T) {
resolvers := &Stub{}
resolvers.MutationResolver.UpdateSomething = func(_ context.Context, input SpecialInput) (s string, err error) {
return "Hello world", nil
}
c := client.New(handler.NewDefaultServer(NewExecutableSchema(Config{Resolvers: resolvers})))
t.Run("mutation with correct input doesn't return error", func(t *testing.T) {
var resp map[string]interface{}
input := map[string]interface{}{
"nesting": map[string]interface{}{
"field": "email@example.com",
},
}
err := c.Post(
`mutation TestMutation($input: SpecialInput!) { updateSomething(input: $input) }`,
&resp,
client.Var("input", input),
)
require.Equal(t, "Hello world", resp["updateSomething"])
require.NoError(t, err)
})
t.Run("mutation with incorrect input returns full path", func(t *testing.T) {
var resp map[string]interface{}
input := map[string]interface{}{
"nesting": map[string]interface{}{
"field": "not-an-email",
},
}
err := c.Post(
`mutation TestMutation($input: SpecialInput!) { updateSomething(input: $input) }`,
&resp,
client.Var("input", input),
)
require.EqualError(t, err, `[{"message":"invalid email format","path":["updateSomething","input","nesting","field"]}]`)
})
}