mock.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 executableSchemaMock struct {
12	MutationFunc func(ctx context.Context, op *ast.OperationDefinition) *graphql.Response
13}
14
15var _ graphql.ExecutableSchema = &executableSchemaMock{}
16
17func (e *executableSchemaMock) Schema() *ast.Schema {
18	return gqlparser.MustLoadSchema(&ast.Source{Input: `
19		schema { query: Query, mutation: Mutation }
20		type Query {
21			empty: String!
22		}
23		scalar Upload
24        type File {
25            id: Int!
26        }
27        input UploadFile {
28            id: Int!
29            file: Upload!
30        }
31        type Mutation {
32            singleUpload(file: Upload!): File!
33            singleUploadWithPayload(req: UploadFile!): File!
34            multipleUpload(files: [Upload!]!): [File!]!
35            multipleUploadWithPayload(req: [UploadFile!]!): [File!]!
36        }
37	`})
38}
39
40func (e *executableSchemaMock) Complexity(typeName, field string, childComplexity int, args map[string]interface{}) (int, bool) {
41	return 0, false
42}
43
44func (e *executableSchemaMock) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
45	return graphql.ErrorResponse(ctx, "queries are not supported")
46}
47
48func (e *executableSchemaMock) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
49	return e.MutationFunc(ctx, op)
50}
51
52func (e *executableSchemaMock) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {
53	return func() *graphql.Response {
54		<-ctx.Done()
55		return nil
56	}
57}