Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add proxy poc #22

Merged
merged 44 commits into from
Mar 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
d42f513
introduce proxy struct/api to organize everything around proxying req…
jensneuse Mar 2, 2019
6d31f2d
add ManualAstMod struct which should hold all the apis to modify the …
jensneuse Mar 2, 2019
c5f3491
extend SelectionSetIterable to also return the set reference
jensneuse Mar 2, 2019
9f1a234
update sets.Value return values
jensneuse Mar 2, 2019
4938a02
update selectionSet iter return values
jensneuse Mar 2, 2019
9e776e1
add proxy.graphqls as blueprint for proxy configuration
jensneuse Mar 2, 2019
5879220
update parser to parse values without allocs
jensneuse Mar 2, 2019
bb255c7
add api to lookup to easily get a slice name (int) from a raw byte slice
jensneuse Mar 2, 2019
8b10e87
make the walker emit empty selection sets which is necessary to easil…
jensneuse Mar 2, 2019
7fd3248
implement poc proxy middleware to remove one field/add another field …
jensneuse Mar 2, 2019
f34f482
simplify proxy.graphqls
jensneuse Mar 4, 2019
eb4ffaf
remove unused fixture
jensneuse Mar 4, 2019
f037ffe
add TypeSystemDefinitionOrderedRootNodes iterator
jensneuse Mar 4, 2019
9cd440a
add iterables to lookup
jensneuse Mar 4, 2019
d718dc0
extend node types
jensneuse Mar 4, 2019
4bc2270
update printer tests to enable type system definition printing for tests
jensneuse Mar 4, 2019
d213f0d
WIP implement type system definition printing
jensneuse Mar 4, 2019
d09c929
update printer fixtures
jensneuse Mar 4, 2019
6dccb21
add walk method for interface-/scalar-/union type definition
jensneuse Mar 4, 2019
146822b
update walker enums
jensneuse Mar 4, 2019
f830b2d
WIP implement type system definition printer
jensneuse Mar 4, 2019
1d9e3c9
WIP update starwars typesystem fixture
jensneuse Mar 4, 2019
8716030
fix node sorting
jensneuse Mar 4, 2019
93a82ea
remove unused code
jensneuse Mar 4, 2019
0c63063
remove unused code
jensneuse Mar 4, 2019
59dc2eb
fix missing description parsing on object type definition parser
jensneuse Mar 4, 2019
bb3b4ee
add missing description parsing to directive definition parser
jensneuse Mar 5, 2019
aa6cce4
add missing description parsing to enum type definition parser
jensneuse Mar 5, 2019
cccea73
add missing description parsing to input object type definition parser
jensneuse Mar 5, 2019
48ea63d
add missing description parsing to interface type definition parser
jensneuse Mar 5, 2019
05696f9
add missing description parsing to scalar type definition parser
jensneuse Mar 5, 2019
f1f58fb
update fixture for type system definition printer
jensneuse Mar 5, 2019
b45c5b7
update test input from generated output by the printer itself (clean …
jensneuse Mar 5, 2019
4c495da
implement type system definition printer
jensneuse Mar 5, 2019
aff606a
fix indentation in test fixture
jensneuse Mar 5, 2019
86dd31a
update lexer fixture due to removed field description
jensneuse Mar 5, 2019
773ba37
remove unnecessary check
jensneuse Mar 5, 2019
1224a41
implement directive printing on type system definition
jensneuse Mar 6, 2019
3b14a05
add directives on type system definition printing test
jensneuse Mar 6, 2019
acd7e49
simplify finding root node
jensneuse Mar 6, 2019
693772a
add test with multiple arguments
jensneuse Mar 6, 2019
2d9a5b0
fix printing with multiple arguments
jensneuse Mar 6, 2019
de4aebf
remove unused code
jensneuse Mar 6, 2019
6c7da2c
Merge pull request #23 from jensneuse/add-typesystem-printer
jensneuse Mar 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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