Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ See pkg/parser/parser_test.go

```
pkg: github.com/jensneuse/graphql-go-tools/pkg/parser
BenchmarkParser-4 50000 24778 ns/op 0 B/op 0 allocs/op
BenchmarkParser-4 50000 24950 ns/op 1 B/op 0 allocs/op
BenchmarkParser-4 50000 25724 ns/op 0 B/op 0 allocs/op
BenchmarkParser-4 50000 25537 ns/op 0 B/op 0 allocs/op
BenchmarkParser-4 100000 21264 ns/op 0 B/op 0 allocs/op
BenchmarkParser-4 100000 21531 ns/op 0 B/op 0 allocs/op
BenchmarkParser-4 100000 21150 ns/op 0 B/op 0 allocs/op
BenchmarkParser-4 100000 21234 ns/op 0 B/op 0 allocs/op
```

In a previous release I found that nested slice structs accounted for huge amounts of gc and decreased performance.
Expand Down
14 changes: 7 additions & 7 deletions pkg/document/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package document
// Argument as specified in
// http://facebook.github.io/graphql/draft/#Argument
type Argument struct {
Name ByteSlice
Name ByteSliceReference
Value int
}

Expand All @@ -15,7 +15,7 @@ func (a Argument) NodeValueReference() int {
panic("implement me")
}

func (a Argument) NodeUnionMemberTypes() []ByteSlice {
func (a Argument) NodeUnionMemberTypes() []ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -51,7 +51,7 @@ func (a Argument) NodeDirectiveDefinitions() []int {
panic("implement me")
}

func (a Argument) NodeImplementsInterfaces() []ByteSlice {
func (a Argument) NodeImplementsInterfaces() []ByteSliceReference {
panic("implement me")
}

Expand All @@ -71,15 +71,15 @@ func (a Argument) NodeArgumentsDefinition() []int {
panic("implement me")
}

func (a Argument) NodeName() string {
return string(a.Name)
func (a Argument) NodeName() ByteSliceReference {
return a.Name
}

func (a Argument) NodeAlias() string {
func (a Argument) NodeAlias() ByteSliceReference {
panic("implement me")
}

func (a Argument) NodeDescription() string {
func (a Argument) NodeDescription() ByteSliceReference {
panic("implement me")
}

Expand Down
14 changes: 0 additions & 14 deletions pkg/document/argumentsdefinition.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
package document

import "bytes"

// ArgumentsDefinition as specified in:
// http://facebook.github.io/graphql/draft/#ArgumentsDefinition
type ArgumentsDefinition []InputValueDefinition

// GetByName returns InputValueDefinition by $name or nil if not found
func (a ArgumentsDefinition) GetByName(name ByteSlice) *InputValueDefinition {

for _, definition := range a {
if bytes.Equal(definition.Name, name) {
return &definition
}
}

return nil
}
5 changes: 5 additions & 0 deletions pkg/document/byteslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ type ByteSlice []byte
func (b ByteSlice) MarshalJSON() ([]byte, error) {
return append(append(literal.QUOTE, b...), literal.QUOTE...), nil
}

type ByteSliceReference struct {
Start uint16
End uint16
}
31 changes: 9 additions & 22 deletions pkg/document/directivedefinition.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package document

import "bytes"

// DirectiveDefinition as specified in
// http://facebook.github.io/graphql/draft/#DirectiveDefinition
type DirectiveDefinition struct {
Description ByteSlice
Name ByteSlice
Description ByteSliceReference
Name ByteSliceReference
ArgumentsDefinition []int
DirectiveLocations DirectiveLocations
}
Expand All @@ -19,16 +17,16 @@ func (d DirectiveDefinition) NodeValueReference() int {
panic("implement me")
}

func (d DirectiveDefinition) NodeName() string {
return string(d.Name)
func (d DirectiveDefinition) NodeName() ByteSliceReference {
return d.Name
}

func (d DirectiveDefinition) NodeAlias() string {
func (d DirectiveDefinition) NodeAlias() ByteSliceReference {
panic("implement me")
}

func (d DirectiveDefinition) NodeDescription() string {
return string(d.Description)
func (d DirectiveDefinition) NodeDescription() ByteSliceReference {
return d.Description
}

func (d DirectiveDefinition) NodeArguments() []int {
Expand Down Expand Up @@ -83,7 +81,7 @@ func (d DirectiveDefinition) NodeDefaultValue() int {
panic("implement me")
}

func (d DirectiveDefinition) NodeImplementsInterfaces() []ByteSlice {
func (d DirectiveDefinition) NodeImplementsInterfaces() []ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -119,7 +117,7 @@ func (d DirectiveDefinition) NodeDirectiveDefinitions() []int {
panic("implement me")
}

func (d DirectiveDefinition) NodeUnionMemberTypes() []ByteSlice {
func (d DirectiveDefinition) NodeUnionMemberTypes() []ByteSliceReference {
panic("implement me")
}

Expand All @@ -136,14 +134,3 @@ func (d DirectiveDefinition) ContainsLocation(location DirectiveLocation) bool {

// DirectiveDefinitions is the plural of DirectiveDefinition
type DirectiveDefinitions []DirectiveDefinition

// GetByName returns the DirectiveDefinition via $name
func (d DirectiveDefinitions) GetByName(name ByteSlice) *DirectiveDefinition {
for _, directive := range d {
if bytes.Equal(directive.Name, name) {
return &directive
}
}

return nil
}
14 changes: 7 additions & 7 deletions pkg/document/directives.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package document
// Directive as specified in:
// http://facebook.github.io/graphql/draft/#Directive
type Directive struct {
Name ByteSlice
Name ByteSliceReference
Arguments []int
}

Expand All @@ -15,7 +15,7 @@ func (d Directive) NodeValueReference() int {
panic("implement me")
}

func (d Directive) NodeUnionMemberTypes() []ByteSlice {
func (d Directive) NodeUnionMemberTypes() []ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -51,7 +51,7 @@ func (d Directive) NodeDirectiveDefinitions() []int {
panic("implement me")
}

func (d Directive) NodeImplementsInterfaces() []ByteSlice {
func (d Directive) NodeImplementsInterfaces() []ByteSliceReference {
panic("implement me")
}

Expand All @@ -71,7 +71,7 @@ func (d Directive) NodeArgumentsDefinition() []int {
panic("implement me")
}

func (d Directive) NodeAlias() string {
func (d Directive) NodeAlias() ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -99,11 +99,11 @@ func (d Directive) NodeInlineFragments() []int {
panic("implement me")
}

func (d Directive) NodeName() string {
return string(d.Name)
func (d Directive) NodeName() ByteSliceReference {
return d.Name
}

func (d Directive) NodeDescription() string {
func (d Directive) NodeDescription() ByteSliceReference {
panic("implement me")
}

Expand Down
40 changes: 9 additions & 31 deletions pkg/document/enumtypedefinition.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package document

import (
"bytes"
)

// EnumTypeDefinition as specified in:
// http://facebook.github.io/graphql/draft/#EnumTypeDefinition
type EnumTypeDefinition struct {
Description ByteSlice
Name ByteSlice
Description ByteSliceReference
Name ByteSliceReference
EnumValuesDefinition []int
Directives []int
}
Expand All @@ -21,7 +17,7 @@ func (e EnumTypeDefinition) NodeValueReference() int {
panic("implement me")
}

func (e EnumTypeDefinition) NodeUnionMemberTypes() []ByteSlice {
func (e EnumTypeDefinition) NodeUnionMemberTypes() []ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -57,7 +53,7 @@ func (e EnumTypeDefinition) NodeDirectiveDefinitions() []int {
panic("implement me")
}

func (e EnumTypeDefinition) NodeImplementsInterfaces() []ByteSlice {
func (e EnumTypeDefinition) NodeImplementsInterfaces() []ByteSliceReference {
panic("implement me")
}

Expand All @@ -77,7 +73,7 @@ func (e EnumTypeDefinition) NodeArgumentsDefinition() []int {
panic("implement me")
}

func (e EnumTypeDefinition) NodeAlias() string {
func (e EnumTypeDefinition) NodeAlias() ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -109,12 +105,12 @@ func (e EnumTypeDefinition) NodeEnumValuesDefinition() []int {
return e.EnumValuesDefinition
}

func (e EnumTypeDefinition) NodeName() string {
return string(e.Name)
func (e EnumTypeDefinition) NodeName() ByteSliceReference {
return e.Name
}

func (e EnumTypeDefinition) NodeDescription() string {
return string(e.Description)
func (e EnumTypeDefinition) NodeDescription() ByteSliceReference {
return e.Description
}

func (e EnumTypeDefinition) NodeArguments() []int {
Expand All @@ -125,23 +121,5 @@ func (e EnumTypeDefinition) NodeDirectives() []int {
return e.Directives
}

// TitleCaseName returns the EnumTypeDefinition's Name
// as title case string. example:
// episode => Episode
func (e EnumTypeDefinition) TitleCaseName() ByteSlice {
return bytes.Title(e.Name)
}

// EnumTypeDefinitions is the plural of EnumTypeDefinition
type EnumTypeDefinitions []EnumTypeDefinition

// HasDefinition returns true if a EnumTypeDefinition with $name is contained
func (e EnumTypeDefinitions) HasDefinition(name ByteSlice) bool {
for _, definition := range e {
if bytes.Equal(definition.Name, name) {
return true
}
}

return false
}
29 changes: 9 additions & 20 deletions pkg/document/enumvaluedefinition.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package document

import (
"bytes"
)

// EnumValueDefinition as specified in:
// http://facebook.github.io/graphql/draft/#EnumValueDefinition
type EnumValueDefinition struct {
Description ByteSlice
EnumValue ByteSlice
Description ByteSliceReference
EnumValue ByteSliceReference
Directives []int
}

Expand All @@ -20,7 +16,7 @@ func (e EnumValueDefinition) NodeValueReference() int {
panic("implement me")
}

func (e EnumValueDefinition) NodeUnionMemberTypes() []ByteSlice {
func (e EnumValueDefinition) NodeUnionMemberTypes() []ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -56,7 +52,7 @@ func (e EnumValueDefinition) NodeDirectiveDefinitions() []int {
panic("implement me")
}

func (e EnumValueDefinition) NodeImplementsInterfaces() []ByteSlice {
func (e EnumValueDefinition) NodeImplementsInterfaces() []ByteSliceReference {
panic("implement me")
}

Expand All @@ -76,7 +72,7 @@ func (e EnumValueDefinition) NodeArgumentsDefinition() []int {
panic("implement me")
}

func (e EnumValueDefinition) NodeAlias() string {
func (e EnumValueDefinition) NodeAlias() ByteSliceReference {
panic("implement me")
}

Expand Down Expand Up @@ -104,12 +100,12 @@ func (e EnumValueDefinition) NodeInlineFragments() []int {
return nil
}

func (e EnumValueDefinition) NodeName() string {
return string(e.EnumValue)
func (e EnumValueDefinition) NodeName() ByteSliceReference {
return e.EnumValue
}

func (e EnumValueDefinition) NodeDescription() string {
return string(e.Description)
func (e EnumValueDefinition) NodeDescription() ByteSliceReference {
return e.Description
}

func (e EnumValueDefinition) NodeArguments() []int {
Expand All @@ -123,10 +119,3 @@ func (e EnumValueDefinition) NodeDirectives() []int {
func (e EnumValueDefinition) NodeEnumValuesDefinition() []int {
return nil
}

// ProperCaseVal returns the EnumValueDefinition's EnumValue
// as proper case string. example:
// NORTH => North
func (e EnumValueDefinition) ProperCaseVal() ByteSlice {
return bytes.Title(bytes.ToLower(e.EnumValue))
}
Loading