Skip to content
Permalink
Browse files

Replumb GraphQL queries for ease of use in integration tests #32

  • Loading branch information...
upvalue committed Nov 24, 2018
1 parent 1aed558 commit 24424a144164a8ac92edb6d7d6d5735e85bb2d60
Showing with 8 additions and 15 deletions.
  1. +1 −1 backend/backend_test.go
  2. +7 −14 backend/graphql.go
@@ -46,7 +46,7 @@ func TestStatistics(t *testing.T) {
// object for testing purposes in my estimation: convert it to json, then use one of the
// many json query libraries to interface with it
func graphqlToJson(t *testing.T, query string) *jsonq.JsonQuery {
result := executeQuery(query, schema)
result := executeQuery(query)

if result.HasErrors() {
t.FailNow()
@@ -454,18 +454,7 @@ var mutationType = graphql.NewObject(graphql.ObjectConfig{
},
})

func executeQuery(query string, schema graphql.Schema) *graphql.Result {
result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: query,
})
if len(result.Errors) > 0 {
fmt.Printf("wrong result, unexpected errors: %v", result.Errors)
}
return result
}

func executeVarQuery(query string, vars map[string]interface{}, schema graphql.Schema) *graphql.Result {
func executeVarQuery(query string, vars map[string]interface{}) *graphql.Result {
result := graphql.Do(graphql.Params{
Schema: schema,
RequestString: query,
@@ -477,6 +466,10 @@ func executeVarQuery(query string, vars map[string]interface{}, schema graphql.S
return result
}

func executeQuery(query string) *graphql.Result {
return executeVarQuery(query, nil)
}

// GraphQL schema object
var schema graphql.Schema
var graphqlinitialized = false
@@ -510,9 +503,9 @@ func graphqlWebInit(m *macaron.Macaron) {
var result *graphql.Result

if vars, ok := body["variables"]; ok {
result = executeVarQuery(body["query"].(string), vars.(map[string]interface{}), schema)
result = executeVarQuery(body["query"].(string), vars.(map[string]interface{}))
} else {
result = executeQuery(body["query"].(string), schema)
result = executeVarQuery(body["query"].(string), nil)

}

0 comments on commit 24424a1

Please sign in to comment.
You can’t perform that action at this time.