forked from graphql-go/graphql
-
Notifications
You must be signed in to change notification settings - Fork 2
/
graphql.go
49 lines (43 loc) · 1.12 KB
/
graphql.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
package graphql
import (
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/language/parser"
"github.com/graphql-go/graphql/language/source"
"golang.org/x/net/context"
)
type Params struct {
Schema Schema
RequestString string
RootObject map[string]interface{}
VariableValues map[string]interface{}
OperationName string
// Context may be provided to pass application-specific per-request
// information to resolve functions.
Context context.Context
}
func Do(p Params) *Result {
source := source.NewSource(&source.Source{
Body: p.RequestString,
Name: "GraphQL request",
})
AST, err := parser.Parse(parser.ParseParams{Source: source})
if err != nil {
return &Result{
Errors: gqlerrors.FormatErrors(err),
}
}
validationResult := ValidateDocument(&p.Schema, AST, nil)
if !validationResult.IsValid {
return &Result{
Errors: validationResult.Errors,
}
}
return Execute(ExecuteParams{
Schema: p.Schema,
Root: p.RootObject,
AST: AST,
OperationName: p.OperationName,
Args: p.VariableValues,
Context: p.Context,
})
}