stub.go

 1package handler
 2
 3import (
 4	"context"
 5
 6	"github.com/99designs/gqlgen/graphql"
 7	"github.com/vektah/gqlparser"
 8	"github.com/vektah/gqlparser/ast"
 9)
10
11type executableSchemaStub struct {
12	NextResp chan struct{}
13}
14
15var _ graphql.ExecutableSchema = &executableSchemaStub{}
16
17func (e *executableSchemaStub) Schema() *ast.Schema {
18	return gqlparser.MustLoadSchema(&ast.Source{Input: `
19		schema { query: Query }
20		type Query {
21			me: User!
22			user(id: Int): User!
23		}
24		type User { name: String! }
25	`})
26}
27
28func (e *executableSchemaStub) Complexity(typeName, field string, childComplexity int, args map[string]interface{}) (int, bool) {
29	return 0, false
30}
31
32func (e *executableSchemaStub) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
33	return &graphql.Response{Data: []byte(`{"name":"test"}`)}
34}
35
36func (e *executableSchemaStub) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
37	return graphql.ErrorResponse(ctx, "mutations are not supported")
38}
39
40func (e *executableSchemaStub) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {
41	return func() *graphql.Response {
42		select {
43		case <-ctx.Done():
44			return nil
45		case <-e.NextResp:
46			return &graphql.Response{
47				Data: []byte(`{"name":"test"}`),
48			}
49		}
50	}
51}