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
3 changes: 2 additions & 1 deletion gometalinter.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"vet"
],
"Exclude": [
"pkg/document/directivelocation_enum.go"
"pkg/document/directivelocation_enum.go",
"../../../../../../../usr/local/go/src/.."
]
}
2 changes: 1 addition & 1 deletion 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 string
Value Value
}

Expand Down
6 changes: 2 additions & 4 deletions pkg/document/argumentsdefinition.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
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 []byte) *InputValueDefinition {
func (a ArgumentsDefinition) GetByName(name string) *InputValueDefinition {

for _, definition := range a {
if bytes.Equal(definition.Name, name) {
if definition.Name == name {
return &definition
}
}
Expand Down
12 changes: 0 additions & 12 deletions pkg/document/byteslice.go

This file was deleted.

10 changes: 4 additions & 6 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 string
Name string
ArgumentsDefinition ArgumentsDefinition
DirectiveLocations DirectiveLocations
}
Expand All @@ -26,9 +24,9 @@ func (d DirectiveDefinition) ContainsLocation(location DirectiveLocation) bool {
type DirectiveDefinitions []DirectiveDefinition

// GetByName returns the DirectiveDefinition via $name
func (d DirectiveDefinitions) GetByName(name []byte) *DirectiveDefinition {
func (d DirectiveDefinitions) GetByName(name string) *DirectiveDefinition {
for _, directive := range d {
if bytes.Equal(directive.Name, name) {
if directive.Name == name {
return &directive
}
}
Expand Down
2 changes: 1 addition & 1 deletion 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 string
Arguments Arguments
}

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

import (
"bytes"
"strings"
)

// EnumTypeDefinition as specified in:
// http://facebook.github.io/graphql/draft/#EnumTypeDefinition
type EnumTypeDefinition struct {
Description ByteSlice
Name ByteSlice
Description string
Name string
EnumValuesDefinition EnumValuesDefinition
Directives Directives
}

// TitleCaseName returns the EnumTypeDefinition's Name
// as title case string. example:
// episode => Episode
func (e EnumTypeDefinition) TitleCaseName() []byte {
return bytes.Title(e.Name)
func (e EnumTypeDefinition) TitleCaseName() string {
return strings.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 []byte) bool {
func (e EnumTypeDefinitions) HasDefinition(name string) bool {
for _, definition := range e {
if bytes.Equal(definition.Name, name) {
if definition.Name == name {
return true
}
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/document/enumvaluedefinition.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package document

import (
"bytes"
"strings"
)

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

// ProperCaseVal returns the EnumValueDefinition's EnumValue
// as proper case string. example:
// NORTH => North
func (e EnumValueDefinition) ProperCaseVal() []byte {
return bytes.Title(bytes.ToLower(e.EnumValue))
func (e EnumValueDefinition) ProperCaseVal() string {
return strings.Title(strings.ToLower(e.EnumValue))
}
4 changes: 2 additions & 2 deletions pkg/document/field.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package document
// Field as specified in:
// http://facebook.github.io/graphql/draft/#Field
type Field struct {
Alias ByteSlice
Name ByteSlice
Alias string
Name string
Arguments Arguments
Directives Directives
SelectionSet SelectionSet
Expand Down
16 changes: 8 additions & 8 deletions pkg/document/fielddefinition.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package document

import (
"bytes"
"github.com/jensneuse/graphql-go-tools/pkg/lexing/literal"
"strings"
)

// FieldDefinition as specified in:
// http://facebook.github.io/graphql/draft/#FieldDefinition
type FieldDefinition struct {
Description ByteSlice
Name ByteSlice
Description string
Name string
ArgumentsDefinition ArgumentsDefinition
Type Type
Directives Directives
}

// NameAsTitle trims all prefixed __ and formats the name with strings.Title
func (f FieldDefinition) NameAsTitle() []byte {
return bytes.Title(bytes.TrimPrefix(f.Name, []byte("__")))
func (f FieldDefinition) NameAsTitle() string {
return strings.Title(strings.TrimPrefix(f.Name, "__"))
}

// NameAsGoTypeName returns the field definition name as a go type name
func (f FieldDefinition) NameAsGoTypeName() []byte {
func (f FieldDefinition) NameAsGoTypeName() string {

name := f.NameAsTitle()
name = append(bytes.ToLower(name[:1]), name[1:]...)
name = strings.ToLower(name[:1]) + name[1:]

if bytes.Equal(name, literal.TYPE) {
if name == literal.TYPE {
name = literal.GRAPHQLTYPE
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/document/fragmentdefinition.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package document

import "bytes"

// FragmentDefinition as specified in
// http://facebook.github.io/graphql/draft/#FragmentDefinition
type FragmentDefinition struct {
FragmentName ByteSlice // but not on
FragmentName string // but not on
TypeCondition NamedType
Directives Directives
SelectionSet SelectionSet
Expand All @@ -15,9 +13,9 @@ type FragmentDefinition struct {
type FragmentDefinitions []FragmentDefinition

// GetByName returns the fragment definition with the given name if contained
func (f FragmentDefinitions) GetByName(name []byte) (FragmentDefinition, bool) {
func (f FragmentDefinitions) GetByName(name string) (FragmentDefinition, bool) {
for _, fragment := range f {
if bytes.Equal(fragment.FragmentName, name) {
if fragment.FragmentName == name {
return fragment, true
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/document/fragmentspread.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package document
// FragmentSpread as specified in:
// http://facebook.github.io/graphql/draft/#FragmentSpread
type FragmentSpread struct {
FragmentName ByteSlice
FragmentName string
Directives Directives
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/document/implementsinterfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package document

// ImplementsInterfaces as specified in:
// http://facebook.github.io/graphql/draft/#ImplementsInterfaces
type ImplementsInterfaces []ByteSlice
type ImplementsInterfaces []string
6 changes: 2 additions & 4 deletions pkg/document/inputfieldsdefinition.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package document

import "bytes"

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

// GetByName returns a InputValueDefinition by $name or nil if not found
func (i InputFieldsDefinition) GetByName(name []byte) *InputValueDefinition {
func (i InputFieldsDefinition) GetByName(name string) *InputValueDefinition {
for _, definition := range i {
if bytes.Equal(definition.Name, name) {
if definition.Name == name {
return &definition
}
}
Expand Down
14 changes: 6 additions & 8 deletions pkg/document/inputobjecttypedefinition.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package document

import "bytes"

// InputObjectTypeDefinition as specified in:
// http://facebook.github.io/graphql/draft/#InputObjectTypeDefinition
type InputObjectTypeDefinition struct {
Description ByteSlice
Name ByteSlice
Description string
Name string
InputFieldsDefinition InputFieldsDefinition
Directives Directives
}
Expand All @@ -15,10 +13,10 @@ type InputObjectTypeDefinition struct {
type InputObjectTypeDefinitions []InputObjectTypeDefinition

// HasDefinition returns true if an InputObjectTypeDefinition with $name is contained
func (i InputObjectTypeDefinitions) HasDefinition(name []byte) bool {
func (i InputObjectTypeDefinitions) HasDefinition(name string) bool {

for _, definition := range i {
if bytes.Equal(definition.Name, name) {
if definition.Name == name {
return true
}
}
Expand All @@ -27,9 +25,9 @@ func (i InputObjectTypeDefinitions) HasDefinition(name []byte) bool {
}

// GetByName returns a InputObjectTypeDefinition by $name or nil if not found
func (i InputObjectTypeDefinitions) GetByName(name []byte) *InputObjectTypeDefinition {
func (i InputObjectTypeDefinitions) GetByName(name string) *InputObjectTypeDefinition {
for _, definition := range i {
if bytes.Equal(definition.Name, name) {
if definition.Name == name {
return &definition
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/document/inputvaluedefinition.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package document
// InputValueDefinition as specified in:
// http://facebook.github.io/graphql/draft/#InputValueDefinition
type InputValueDefinition struct {
Description ByteSlice
Name ByteSlice
Description string
Name string
Type Type
DefaultValue Value
Directives Directives
Expand Down
10 changes: 4 additions & 6 deletions pkg/document/interfacetypedefinition.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package document

import "bytes"

// InterfaceTypeDefinition as specified in:
// http://facebook.github.io/graphql/draft/#InterfaceTypeDefinition
type InterfaceTypeDefinition struct {
Description ByteSlice
Name ByteSlice
Description string
Name string
FieldsDefinition FieldsDefinition
Directives Directives
}
Expand All @@ -15,9 +13,9 @@ type InterfaceTypeDefinition struct {
type InterfaceTypeDefinitions []InterfaceTypeDefinition

// GetByName returns the interface type definition by name if contained
func (i InterfaceTypeDefinitions) GetByName(name []byte) *InterfaceTypeDefinition {
func (i InterfaceTypeDefinitions) GetByName(name string) *InterfaceTypeDefinition {
for _, iFace := range i {
if bytes.Equal(iFace.Name, name) {
if iFace.Name == name {
return &iFace
}
}
Expand Down
14 changes: 6 additions & 8 deletions pkg/document/listtype.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package document

import "bytes"

// ListType as specified in:
// https://facebook.github.io/graphql/draft/#ListType
type ListType struct {
Expand All @@ -10,16 +8,16 @@ type ListType struct {
}

// TypeName returns the unwrapped (in case of list type) type name
func (l ListType) TypeName() []byte {
for bytes.Equal(l.Type.GetTypeKind(), ListTypeKind) {
func (l ListType) TypeName() string {
for l.Type.GetTypeKind() == ListTypeKind {
l = l.Type.(ListType)
}
return l.Type.(NamedType).Name
}

// IsBaseType returns if the unwrapped (in case of list type) type name is a base type
func (l ListType) IsBaseType() bool {
for bytes.Equal(l.Type.GetTypeKind(), ListTypeKind) {
for l.Type.GetTypeKind() == ListTypeKind {
l = l.Type.(ListType)
}
return l.Type.(NamedType).IsBaseType()
Expand All @@ -31,9 +29,9 @@ func (l ListType) GetTypeKind() TypeKind {
}

// AsGoType returns the GraphQL List Type Name as valid go type
func (l ListType) AsGoType() []byte {
return append([]byte("[]"), l.Type.AsGoType()...)
func (l ListType) AsGoType() string {
return "[]" + l.Type.AsGoType()
}

// ListTypeKind marks a Type as ListType
var ListTypeKind TypeKind = []byte("ListType")
var ListTypeKind TypeKind = "ListType"
Loading