1 Star 0 Fork 0

麦冬果果/graphql-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
graphql.go 1.63 KB
一键复制 编辑 原始数据 按行查看 历史
package graphql
import (
"context"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/language/parser"
"github.com/graphql-go/graphql/language/source"
)
type Params struct {
// The GraphQL type system to use when validating and executing a query.
Schema Schema
// A GraphQL language formatted string representing the requested operation.
RequestString string
// The value provided as the first argument to resolver functions on the top
// level type (e.g. the query object type).
RootObject map[string]interface{}
// A mapping of variable name to runtime value to use for all variables
// defined in the requestString.
VariableValues map[string]interface{}
// The name of the operation to use if requestString contains multiple
// possible operations. Can be omitted if requestString contains only
// one operation.
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: []byte(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,
})
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mdgg0816/graphql-go.git
git@gitee.com:mdgg0816/graphql-go.git
mdgg0816
graphql-go
graphql-go
v0.7.6

搜索帮助