예제 #1
0
파일: graphql.go 프로젝트: Fugiman/graphql
func Graphql(p Params, resultChannel chan *Result) {
	source := source.NewSource(&source.Source{
		Body: p.RequestString,
		Name: "GraphQL request",
	})
	AST, err := parser.Parse(parser.ParseParams{Source: source})
	if err != nil {
		result := Result{
			Errors: gqlerrors.FormatErrors(err),
		}
		resultChannel <- &result
		return
	}
	validationResult := ValidateDocument(p.Schema, AST)

	if !validationResult.IsValid {
		result := Result{
			Errors: validationResult.Errors,
		}
		resultChannel <- &result
		return
	} else {
		ep := ExecuteParams{
			Schema:        p.Schema,
			Root:          p.RootObject,
			AST:           AST,
			OperationName: p.OperationName,
			Args:          p.VariableValues,
		}
		Execute(ep, resultChannel)
		return
	}
}
예제 #2
0
func parse(t *testing.T, query string) *ast.Document {
	astDoc, err := parser.Parse(parser.ParseParams{
		Source: query,
		Options: parser.ParseOptions{
			NoLocation: true,
		},
	})
	if err != nil {
		t.Fatalf("Parse failed: %v", err)
	}
	return astDoc
}
예제 #3
0
파일: testutil.go 프로젝트: Fugiman/graphql
func TestParse(t *testing.T, query string) *ast.Document {
	astDoc, err := parser.Parse(parser.ParseParams{
		Source: query,
		Options: parser.ParseOptions{
			// include source, for error reporting
			NoSource: false,
		},
	})
	if err != nil {
		t.Fatalf("Parse failed: %v", err)
	}
	return astDoc
}