miscellaneous test coverage

This commit is contained in:
Ben Kraft
2021-04-02 16:34:15 -07:00
parent 4669ea00d0
commit 0432f3f434
6 changed files with 83 additions and 8 deletions
-1
View File
@@ -98,7 +98,6 @@ Config options:
Other:
- (+) improved validation and error checking
- (+) more tests
- (+) documentation
- get a designer to fix my bad logo-thing
- custom scalar types (or custom mappings for standard scalars, if you want a special ID type say)
+10
View File
@@ -0,0 +1,10 @@
# SimpleMutation creates a user.
#
# It has a long doc-comment, to test that we handle that correctly.
# What a long comment indeed.
mutation SimpleMutation($name: String!) {
createUser(name: $name) {
id
name
}
}
+46
View File
@@ -0,0 +1,46 @@
package test
// Code generated by github.com/Khan/genqlient, DO NOT EDIT.
import (
"github.com/Khan/genqlient/graphql"
)
type SimpleMutationCreateUser struct {
Id string `json:"id"`
Name string `json:"name"`
}
type SimpleMutationResponse struct {
CreateUser SimpleMutationCreateUser `json:"createUser"`
}
// SimpleMutation creates a user.
//
// It has a long doc-comment, to test that we handle that correctly.
// What a long comment indeed.
func SimpleMutation(
client graphql.Client,
name string,
) (*SimpleMutationResponse, error) {
variables := map[string]interface{}{
"name": name,
}
var retval SimpleMutationResponse
err := client.MakeRequest(
nil,
"SimpleMutation",
`
mutation SimpleMutation ($name: String!) {
createUser(name: $name) {
id
name
}
}
`,
&retval,
variables,
)
return &retval, err
}
+9
View File
@@ -0,0 +1,9 @@
{
"operations": [
{
"operationName": "SimpleMutation",
"query": "\nmutation SimpleMutation ($name: String!) {\n\tcreateUser(name: $name) {\n\t\tid\n\t\tname\n\t}\n}\n",
"sourceLocation": "testdata/queries/SimpleMutation.graphql"
}
]
}
+4
View File
@@ -61,3 +61,7 @@ type Query {
root: Topic!
randomLeaf: LeafContent!
}
type Mutation {
createUser(name: String!, email: String): User
}
+14 -7
View File
@@ -14,16 +14,19 @@ type typeBuilder struct {
*generator
}
func (g *generator) baseTypeForOperation(operation ast.Operation) *ast.Definition {
func (g *generator) baseTypeForOperation(operation ast.Operation) (*ast.Definition, error) {
switch operation {
case ast.Query:
return g.schema.Query
return g.schema.Query, nil
case ast.Mutation:
return g.schema.Mutation
return g.schema.Mutation, nil
case ast.Subscription:
return g.schema.Subscription
if !allowBrokenFeatures {
return nil, fmt.Errorf("genqlient does not yet support subscriptions")
}
return g.schema.Subscription, nil
default:
panic(fmt.Sprintf("unexpected operation: %v", operation))
return nil, fmt.Errorf("unexpected operation: %v", operation)
}
}
@@ -41,8 +44,12 @@ func (g *generator) getTypeForOperation(operation *ast.OperationDefinition) (nam
return "", err
}
return g.addTypeForDefinition(
operation.Name, name, g.baseTypeForOperation(operation.Operation), fields)
baseType, err := g.baseTypeForOperation(operation.Operation)
if err != nil {
return "", err
}
return g.addTypeForDefinition(operation.Name, name, baseType, fields)
}
var builtinTypes = map[string]string{