-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathmutation_test.go
56 lines (53 loc) · 1.26 KB
/
mutation_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
52
53
54
55
56
package starwars_test
import (
"reflect"
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/testutil"
"github.com/graphql-go/relay/examples/starwars"
)
func TestMutation_CorrectlyMutatesTheDataSet(t *testing.T) {
query := `
mutation AddBWingQuery($input: IntroduceShipInput!) {
introduceShip(input: $input) {
ship {
id
name
}
faction {
name
}
clientMutationId
}
}
`
params := map[string]interface{}{
"input": map[string]interface{}{
"shipName": "B-Wing",
"factionId": "1",
"clientMutationId": "abcde",
},
}
expected := &graphql.Result{
Data: map[string]interface{}{
"introduceShip": map[string]interface{}{
"ship": map[string]interface{}{
"id": "U2hpcDoxMA==",
"name": "B-Wing",
},
"faction": map[string]interface{}{
"name": "Alliance to Restore the Republic",
},
"clientMutationId": "abcde",
},
},
}
result := graphql.Do(graphql.Params{
Schema: starwars.Schema,
RequestString: query,
VariableValues: params,
})
if !reflect.DeepEqual(result, expected) {
t.Fatalf("wrong result, graphql result diff: %v", testutil.Diff(expected, result))
}
}