aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/99designs/gqlgen/handler/mock.go
blob: 3e70cf036bfb854cbedb89fff1b219204d5072aa (plain) (blame)
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
package handler

import (
	"context"

	"github.com/99designs/gqlgen/graphql"
	"github.com/vektah/gqlparser"
	"github.com/vektah/gqlparser/ast"
)

type executableSchemaMock struct {
	MutationFunc func(ctx context.Context, op *ast.OperationDefinition) *graphql.Response
}

var _ graphql.ExecutableSchema = &executableSchemaMock{}

func (e *executableSchemaMock) Schema() *ast.Schema {
	return gqlparser.MustLoadSchema(&ast.Source{Input: `
		schema { query: Query, mutation: Mutation }
		type Query {
			empty: String!
		}
		scalar Upload
        type File {
            id: Int!
        }
        input UploadFile {
            id: Int!
            file: Upload!
        }
        type Mutation {
            singleUpload(file: Upload!): File!
            singleUploadWithPayload(req: UploadFile!): File!
            multipleUpload(files: [Upload!]!): [File!]!
            multipleUploadWithPayload(req: [UploadFile!]!): [File!]!
        }
	`})
}

func (e *executableSchemaMock) Complexity(typeName, field string, childComplexity int, args map[string]interface{}) (int, bool) {
	return 0, false
}

func (e *executableSchemaMock) Query(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
	return graphql.ErrorResponse(ctx, "queries are not supported")
}

func (e *executableSchemaMock) Mutation(ctx context.Context, op *ast.OperationDefinition) *graphql.Response {
	return e.MutationFunc(ctx, op)
}

func (e *executableSchemaMock) Subscription(ctx context.Context, op *ast.OperationDefinition) func() *graphql.Response {
	return func() *graphql.Response {
		<-ctx.Done()
		return nil
	}
}