-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphql_test.go
111 lines (95 loc) · 2.13 KB
/
graphql_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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package cloudcms
import (
"fmt"
"testing"
)
func TestGraphQL(t *testing.T) {
session, err := ConnectDefault()
if err != nil {
t.Fatal(err)
}
repository, err := session.CreateRepository(nil)
if err != nil {
t.Fatal(err)
}
repositoryId := ExtractId(&repository)
defer session.DeleteRepository(repositoryId)
branchId := "master"
bookTypeId, err := session.CreateNode(repositoryId, branchId, JsonObject{
"_qname": "custom:book",
"_type": "d:type",
"type": "object",
"description": "Node List Test Book Type",
"properties": JsonObject{
"title": JsonObject{
"type": "string",
},
"description": JsonObject{
"type": "string",
},
"author": JsonObject{
"type": "string",
},
},
}, nil)
if err != nil {
t.Fatal(err)
}
bookType, _ := session.ReadNode(repositoryId, branchId, bookTypeId)
fmt.Printf("%v\n", bookType)
schema, err := session.GraphQLSchema(repositoryId, branchId)
if err != nil {
t.Fatal(err)
}
if schema == "" {
t.Fatal("failed to find schema")
}
fmt.Println(schema)
_, err = session.CreateNode(repositoryId, branchId, JsonObject{
"title": "hello",
"description": "this is a book about salutations",
"author": "mr bean",
"_type": "custom:book",
}, nil)
if err != nil {
t.Fatal(err)
}
_, err = session.CreateNode(repositoryId, branchId, JsonObject{
"title": "goodbye",
"description": "leave",
"author": "guillermo del toro",
"_type": "custom:book",
}, nil)
if err != nil {
t.Fatal(err)
}
query := `
query {
custom_books {
title
author
}
}
`
result, err := session.GraphQLQuery(repositoryId, branchId, query, "", nil)
if err != nil {
t.Fatal(err)
}
if result["data"] == nil {
t.Fatal("No graphql response data")
}
dataObj := result.GetObject("data")
if dataObj == nil {
t.Fatal("data not an object")
}
if dataObj["custom_books"] == nil {
t.Fatal("No books in response data")
}
booksArr := dataObj["custom_books"].([]interface{})
if booksArr == nil {
t.Fatal("no custom_books in response")
}
if len(booksArr) != 2 {
t.Fatal("wrong number of books in response data")
}
}