aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/vektah/gqlparser/gqlparser.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/vektah/gqlparser/gqlparser.go')
-rw-r--r--vendor/github.com/vektah/gqlparser/gqlparser.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/github.com/vektah/gqlparser/gqlparser.go b/vendor/github.com/vektah/gqlparser/gqlparser.go
new file mode 100644
index 00000000..71e46407
--- /dev/null
+++ b/vendor/github.com/vektah/gqlparser/gqlparser.go
@@ -0,0 +1,42 @@
+package gqlparser
+
+import (
+ "github.com/vektah/gqlparser/ast"
+ "github.com/vektah/gqlparser/gqlerror"
+ "github.com/vektah/gqlparser/parser"
+ "github.com/vektah/gqlparser/validator"
+ _ "github.com/vektah/gqlparser/validator/rules"
+)
+
+func LoadSchema(str ...*ast.Source) (*ast.Schema, *gqlerror.Error) {
+ return validator.LoadSchema(append([]*ast.Source{validator.Prelude}, str...)...)
+}
+
+func MustLoadSchema(str ...*ast.Source) *ast.Schema {
+ s, err := validator.LoadSchema(append([]*ast.Source{validator.Prelude}, str...)...)
+ if err != nil {
+ panic(err)
+ }
+ return s
+}
+
+func LoadQuery(schema *ast.Schema, str string) (*ast.QueryDocument, gqlerror.List) {
+ query, err := parser.ParseQuery(&ast.Source{Input: str})
+ if err != nil {
+ return nil, gqlerror.List{err}
+ }
+ errs := validator.Validate(schema, query)
+ if errs != nil {
+ return nil, errs
+ }
+
+ return query, nil
+}
+
+func MustLoadQuery(schema *ast.Schema, str string) *ast.QueryDocument {
+ q, err := LoadQuery(schema, str)
+ if err != nil {
+ panic(err)
+ }
+ return q
+}