-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
101 lines (89 loc) · 2.47 KB
/
context.go
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package gql
import (
"context"
"sync"
"github.com/rigglo/gql/pkg/language/ast"
)
type gqlCtx struct {
ctx context.Context
mu sync.Mutex
sem chan struct{}
concurrency bool
concurrencyLimit int
res *Result
errMu sync.Mutex
schema *Schema
doc *ast.Document
params *Params
operation *ast.Operation
variables map[string]interface{}
types map[string]Type
implementors map[string][]Type
directives map[string]Directive
fragments map[string]*ast.Fragment
fragmentUsage map[string]bool
variableDefs map[string]map[string]*ast.Variable
variableUsages map[string]map[string]struct{}
extensions []Extension
}
func newContext(ctx context.Context, schema *Schema, doc *ast.Document, params *Params, concurrencyLimit int, concurrency bool) *gqlCtx {
return &gqlCtx{
ctx: ctx,
sem: make(chan struct{}, concurrencyLimit),
concurrency: concurrency,
concurrencyLimit: concurrencyLimit,
res: &Result{},
schema: schema,
doc: doc,
params: params,
types: map[string]Type{},
implementors: map[string][]Type{},
directives: map[string]Directive{},
fragments: map[string]*ast.Fragment{},
fragmentUsage: map[string]bool{},
variables: map[string]interface{}{},
variableDefs: map[string]map[string]*ast.Variable{},
variableUsages: map[string]map[string]struct{}{},
}
}
func (c *gqlCtx) addErr(err *Error) {
c.errMu.Lock()
defer c.errMu.Unlock()
c.res.Errors = append(c.res.Errors, err)
}
/*
Context for the field resolver functions
*/
type Context interface {
// Context returns the original context that was given to the executor
Context() context.Context
// Path of the field
Path() []interface{}
// Args of the field
Args() map[string]interface{}
// Parent object's data
Parent() interface{}
}
type resolveContext struct {
ctx context.Context
gqlCtx *gqlCtx
path []interface{}
fields []string
args map[string]interface{}
parent interface{}
}
func (r *resolveContext) Context() context.Context {
return r.ctx
}
func (r *resolveContext) Path() []interface{} {
return r.path
}
func (r *resolveContext) Fields() []string {
return r.fields
}
func (r *resolveContext) Args() map[string]interface{} {
return r.args
}
func (r *resolveContext) Parent() interface{} {
return r.parent
}