Skip to content

Commit

Permalink
Merge pull request #22 from jensneuse/add-proxy
Browse files Browse the repository at this point in the history
add proxy poc
  • Loading branch information
jensneuse committed Mar 6, 2019
2 parents bda7853 + 6c7da2c commit 366d9ef
Show file tree
Hide file tree
Showing 34 changed files with 2,064 additions and 514 deletions.
450 changes: 150 additions & 300 deletions pkg/lexer/fixtures/introspection_lexed.golden

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions pkg/lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ func (l *Lexer) SetTypeSystemInput(input []byte) error {

func (l *Lexer) SetExecutableInput(input []byte) error {

//l.input = append(l.input[:l.typeSystemEndPosition], input...)

l.input = l.input[:l.typeSystemEndPosition]
l.input = append(l.input, input...)

Expand Down
4 changes: 0 additions & 4 deletions pkg/lexing/position/position.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ func (p *Position) MergeEndIntoEnd(position Position) {
p.CharEnd = position.CharEnd
}

func (p *Position) IsSet() bool {
return p.CharStart != 0 || p.CharEnd != 0 || p.LineStart != 0 || p.LineEnd != 0
}

func (p *Position) IsBefore(another Position) bool {
return p.LineEnd < another.LineStart ||
p.LineEnd == another.LineStart && p.CharEnd < another.CharStart
Expand Down
65 changes: 0 additions & 65 deletions pkg/lexing/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ type Token struct {
Keyword keyword.Keyword
Literal document.ByteSliceReference
TextPosition position.Position
Description string
}

func (t Token) String() string {
Expand All @@ -29,67 +28,3 @@ func (t *Token) SetEnd(inputPosition int, textPosition position.Position) {
t.TextPosition.LineEnd = textPosition.LineStart
t.TextPosition.CharEnd = textPosition.CharStart
}

/*var (
EOF = Token{
Keyword: keyword.EOF,
Literal: literal.EOF,
}
Pipe = Token{
Keyword: keyword.PIPE,
Literal: literal.PIPE,
}
Dot = Token{
Keyword: keyword.DOT,
Literal: literal.DOT,
}
Spread = Token{
Keyword: keyword.SPREAD,
Literal: literal.SPREAD,
}
Equals = Token{
Keyword: keyword.EQUALS,
Literal: literal.EQUALS,
}
At = Token{
Keyword: keyword.AT,
Literal: literal.AT,
}
Colon = Token{
Keyword: keyword.COLON,
Literal: literal.COLON,
}
Bang = Token{
Keyword: keyword.BANG,
Literal: literal.BANG,
}
BracketOpen = Token{
Keyword: keyword.BRACKETOPEN,
Literal: literal.BRACKETOPEN,
}
BracketClose = Token{
Keyword: keyword.BRACKETCLOSE,
Literal: literal.BRACKETCLOSE,
}
CurlyBracketOpen = Token{
Keyword: keyword.CURLYBRACKETOPEN,
Literal: literal.CURLYBRACKETOPEN,
}
CurlyBracketClose = Token{
Keyword: keyword.CURLYBRACKETCLOSE,
Literal: literal.CURLYBRACKETCLOSE,
}
SquaredBracketOpen = Token{
Keyword: keyword.SQUAREBRACKETOPEN,
Literal: literal.SQUAREBRACKETOPEN,
}
SquaredBracketClose = Token{
Keyword: keyword.SQUAREBRACKETCLOSE,
Literal: literal.SQUAREBRACKETCLOSE,
}
And = Token{
Keyword: keyword.AND,
Literal: literal.AND,
}
)
*/
45 changes: 42 additions & 3 deletions pkg/lookup/iterable.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package lookup

import "github.com/jensneuse/graphql-go-tools/pkg/document"
import (
"github.com/jensneuse/graphql-go-tools/pkg/document"
"sort"
)

type Iterable struct {
current int
Expand Down Expand Up @@ -92,9 +95,13 @@ type SelectionSetIterable struct {
Iterable
}

func (s *SelectionSetIterable) Value() (set document.SelectionSet, ref, parent int) {
func (s *SelectionSetIterable) Value() (set document.SelectionSet, nodeRef, setRef, parent int) {
node := s.node()
return s.w.l.SelectionSet(node.Ref), s.ref(), node.Parent
nodeRef = s.ref()
parent = node.Parent
setRef = node.Ref
set = s.w.l.SelectionSet(setRef)
return
}

func (w *Walker) SelectionSetIterable() SelectionSetIterable {
Expand All @@ -119,3 +126,35 @@ func (w *Walker) FieldsIterable() FieldsIterable {
Iterable: w.newIterable(w.c.fields),
}
}

type TypeSystemDefinitionOrderedRootNodes struct {
Iterable
}

func (t *TypeSystemDefinitionOrderedRootNodes) Value() (ref int, kind NodeKind) {
node := t.node()
ref = node.Ref
kind = node.Kind
return
}

func (w *Walker) TypeSystemDefinitionOrderedRootNodes() TypeSystemDefinitionOrderedRootNodes {

refs := w.c.rootNodes[:0]

for i := range w.nodes {
if w.nodes[i].Parent == -1 {
refs = append(refs, i)
}
}

sort.Slice(refs, func(i, j int) bool {
left := refs[i]
right := refs[j]
return w.nodes[left].Position.LineStart < w.nodes[right].Position.LineStart
})

return TypeSystemDefinitionOrderedRootNodes{
Iterable: w.newIterable(refs),
}
}
66 changes: 66 additions & 0 deletions pkg/lookup/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,35 @@ func (l *Lookup) Type(i int) document.Type {
return l.p.ParsedDefinitions.Types[i]
}

type ObjectTypeDefinitionIterable struct {
current int
refs []int
l *Lookup
}

func (o *ObjectTypeDefinitionIterable) Next() bool {
o.current++
return len(o.refs)-1 >= o.current
}

func (o *ObjectTypeDefinitionIterable) Value() (ref int, definition document.ObjectTypeDefinition) {
ref = o.refs[o.current]
definition = o.l.ObjectTypeDefinition(ref)
return
}

func (l *Lookup) ObjectTypeDefinitionIterable(refs []int) ObjectTypeDefinitionIterable {
return ObjectTypeDefinitionIterable{
current: -1,
refs: refs,
l: l,
}
}

func (l *Lookup) ObjectTypeDefinition(ref int) document.ObjectTypeDefinition {
return l.p.ParsedDefinitions.ObjectTypeDefinitions[ref]
}

func (l *Lookup) ObjectTypeDefinitionByName(name int) (definition document.ObjectTypeDefinition, exists bool) {
for i := range l.p.ParsedDefinitions.ObjectTypeDefinitions {
if name == l.p.ParsedDefinitions.ObjectTypeDefinitions[i].Name {
Expand All @@ -233,6 +262,31 @@ func (l *Lookup) ScalarTypeDefinitionByName(name int) (document.ScalarTypeDefini
return document.ScalarTypeDefinition{}, false
}

type EnumTypeDefinitionIterable struct {
l *Lookup
refs []int
current int
}

func (e *EnumTypeDefinitionIterable) Next() bool {
e.current++
return len(e.refs)-1 >= e.current
}

func (e *EnumTypeDefinitionIterable) Value() (ref int, definition document.EnumTypeDefinition) {
ref = e.refs[e.current]
definition = e.l.p.ParsedDefinitions.EnumTypeDefinitions[ref]
return
}

func (l *Lookup) EnumTypeDefinitionIterable(refs []int) EnumTypeDefinitionIterable {
return EnumTypeDefinitionIterable{
current: -1,
refs: refs,
l: l,
}
}

func (l *Lookup) EnumTypeDefinitionByName(name int) (document.EnumTypeDefinition, bool) {
for _, definition := range l.p.ParsedDefinitions.EnumTypeDefinitions {
if name == definition.Name {
Expand Down Expand Up @@ -1533,3 +1587,15 @@ func (l *Lookup) InlineFragmentsDeepEqual(left, right document.InlineFragment) b
func (l *Lookup) FragmentSpreadsDeepEqual(left, right document.FragmentSpread) bool {
return left.FragmentName == right.FragmentName
}

func (l *Lookup) ByteSliceName(slice []byte) (name int) {
length := uint16(len(slice))
for i := range l.p.ParsedDefinitions.ByteSliceReferences {
if l.p.ParsedDefinitions.ByteSliceReferences[i].Length() == length {
if bytes.Equal(l.ByteSlice(l.p.ParsedDefinitions.ByteSliceReferences[i]), slice) {
return i
}
}
}
return -1
}
4 changes: 2 additions & 2 deletions pkg/lookup/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestLookup(t *testing.T) {
if !iter.Next() {
panic("mustHaveSelectionSetTypeNames: want next")
}
set, _, parent := iter.Value()
set, _, _, parent := iter.Value()
typeName := walker.SelectionSetTypeName(set, parent)
got := string(walker.l.CachedName(typeName))
if want != got {
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestLookup(t *testing.T) {
if !iter.Next() {
panic("mustHaveSelectionSets: want next set")
}
set, _, parent := iter.Value()
set, _, _, parent := iter.Value()
typeName := walker.SelectionSetTypeName(set, parent)
got := string(walker.l.CachedName(typeName))
if want.name != got {
Expand Down
Loading

0 comments on commit 366d9ef

Please sign in to comment.