blob: a077ce38619436f4281fae7863d0bdf573f26cc0 [file] [log] [blame]
giolekvac76b21b2020-04-18 19:28:43 +04001package schema
2
3import (
4 "github.com/vektah/gqlparser/ast"
5 "github.com/vektah/gqlparser/parser"
6)
7
8type SchemaStore interface {
9 Schema() *ast.SchemaDocument
10 SetSchema(gqlSchema string) error
11 AddSchema(gqlSchema string) error
12}
13
14type InMemorySchemaStore struct {
15 gqlSchema string
16 schema *ast.SchemaDocument
17}
18
19func NewInMemorySchemaStore() SchemaStore {
20 return &InMemorySchemaStore{gqlSchema: ""}
21}
22
23func (s *InMemorySchemaStore) Schema() *ast.SchemaDocument {
24 return s.schema
25}
26
27func (s *InMemorySchemaStore) AddSchema(gqlSchema string) error {
28 return s.SetSchema(s.gqlSchema + gqlSchema)
29}
30
31func (s *InMemorySchemaStore) SetSchema(gqlSchema string) error {
32 schema, err := parser.ParseSchema(&ast.Source{Input: gqlSchema})
33 if err != nil {
34 return err
35 }
36 s.schema = schema
37 return nil
38}