Skip to content

Commit

Permalink
support for entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
neelance committed Oct 13, 2016
1 parent 0b3d103 commit 2f9ce9b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion graphql.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s *Schema) Exec(queryString string) (res []byte, errRes error) {
return nil, err
}

rawRes := exec(s, s.Types["Query"], q, s.resolver)
rawRes := exec(s, s.Types[s.EntryPoints["query"]], q, s.resolver)
return json.Marshal(rawRes)
}

Expand Down
8 changes: 8 additions & 0 deletions graphql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ func (r *helloWorldResolver) Hello() string {
}

var starWarsSchema = `
schema {
query: Query
}
type Query {
hero: User
human(id: ID): User
Expand Down Expand Up @@ -83,6 +87,10 @@ var tests = []struct {
{
name: "HelloWorld",
schema: `
schema {
query: Query
}
type Query {
hello: String
}
Expand Down
17 changes: 14 additions & 3 deletions internal/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import (
)

type Schema struct {
Types map[string]*Object
EntryPoints map[string]string
Types map[string]*Object
}

type Type interface{}
Expand Down Expand Up @@ -55,16 +56,26 @@ func Parse(schemaString string, filename string) (res *Schema, errRes error) {

func parseSchema(l *lexer.Lexer) *Schema {
s := &Schema{
Types: make(map[string]*Object),
EntryPoints: make(map[string]string),
Types: make(map[string]*Object),
}

for l.Peek() != scanner.EOF {
switch l.ConsumeIdent() {
case "schema":
l.ConsumeToken('{')
for l.Peek() != '}' {
name := l.ConsumeIdent()
l.ConsumeToken(':')
typ := l.ConsumeIdent()
s.EntryPoints[name] = typ
}
l.ConsumeToken('}')
case "type":
name, obj := parseTypeDecl(l)
s.Types[name] = obj
default:
l.UnexpectedSyntaxError(`"type"`)
l.UnexpectedSyntaxError(`"schema" or "type"`)
}
}

Expand Down

0 comments on commit 2f9ce9b

Please sign in to comment.