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

fix unpass testing #319

Merged
merged 3 commits into from
Apr 13, 2018
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: 2 additions & 6 deletions language/ast/arguments.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ func NewArgument(arg *Argument) *Argument {
if arg == nil {
arg = &Argument{}
}
return &Argument{
Kind: kinds.Argument,
Loc: arg.Loc,
Name: arg.Name,
Value: arg.Value,
}
arg.Kind = kinds.Argument
return arg
}

func (arg *Argument) GetKind() string {
Expand Down
20 changes: 4 additions & 16 deletions language/ast/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,8 @@ func NewOperationDefinition(op *OperationDefinition) *OperationDefinition {
if op == nil {
op = &OperationDefinition{}
}
return &OperationDefinition{
Kind: kinds.OperationDefinition,
Loc: op.Loc,
Operation: op.Operation,
Name: op.Name,
VariableDefinitions: op.VariableDefinitions,
Directives: op.Directives,
SelectionSet: op.SelectionSet,
}
op.Kind = kinds.OperationDefinition
return op
}

func (op *OperationDefinition) GetKind() string {
Expand Down Expand Up @@ -143,13 +136,8 @@ func NewVariableDefinition(vd *VariableDefinition) *VariableDefinition {
if vd == nil {
vd = &VariableDefinition{}
}
return &VariableDefinition{
Kind: kinds.VariableDefinition,
Loc: vd.Loc,
Variable: vd.Variable,
Type: vd.Type,
DefaultValue: vd.DefaultValue,
}
vd.Kind = kinds.VariableDefinition
return vd
}

func (vd *VariableDefinition) GetKind() string {
Expand Down
7 changes: 2 additions & 5 deletions language/ast/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ func NewName(node *Name) *Name {
if node == nil {
node = &Name{}
}
return &Name{
Kind: kinds.Name,
Value: node.Value,
Loc: node.Loc,
}
node.Kind = kinds.Name
return node
}

func (node *Name) GetKind() string {
Expand Down
18 changes: 4 additions & 14 deletions language/ast/selections.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,8 @@ func NewField(f *Field) *Field {
if f == nil {
f = &Field{}
}
return &Field{
Kind: kinds.Field,
Loc: f.Loc,
Alias: f.Alias,
Name: f.Name,
Arguments: f.Arguments,
Directives: f.Directives,
SelectionSet: f.SelectionSet,
}
f.Kind = kinds.Field
return f
}

func (f *Field) GetKind() string {
Expand Down Expand Up @@ -128,11 +121,8 @@ func NewSelectionSet(ss *SelectionSet) *SelectionSet {
if ss == nil {
ss = &SelectionSet{}
}
return &SelectionSet{
Kind: kinds.SelectionSet,
Loc: ss.Loc,
Selections: ss.Selections,
}
ss.Kind = kinds.SelectionSet
return ss
}

func (ss *SelectionSet) GetKind() string {
Expand Down
7 changes: 2 additions & 5 deletions language/ast/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@ func NewNamed(t *Named) *Named {
if t == nil {
t = &Named{}
}
return &Named{
Kind: kinds.Named,
Loc: t.Loc,
Name: t.Name,
}
t.Kind = kinds.Named
return t
}

func (t *Named) GetKind() string {
Expand Down
7 changes: 2 additions & 5 deletions language/ast/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ func NewVariable(v *Variable) *Variable {
if v == nil {
v = &Variable{}
}
return &Variable{
Kind: kinds.Variable,
Loc: v.Loc,
Name: v.Name,
}
v.Kind = kinds.Variable
return v
}

func (v *Variable) GetKind() string {
Expand Down
115 changes: 56 additions & 59 deletions language/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,20 +249,18 @@ func parseOperationType(parser *Parser) (string, error) {
*/
func parseVariableDefinitions(parser *Parser) ([]*ast.VariableDefinition, error) {
variableDefinitions := []*ast.VariableDefinition{}
if peek(parser, lexer.TokenKind[lexer.PAREN_L]) {
vdefs, err := reverse(parser,
lexer.TokenKind[lexer.PAREN_L], parseVariableDefinition, lexer.TokenKind[lexer.PAREN_R],
true,
)
if !peek(parser, lexer.TokenKind[lexer.PAREN_L]) {
return variableDefinitions, nil
}
if vdefs, err := reverse(parser,
lexer.TokenKind[lexer.PAREN_L], parseVariableDefinition, lexer.TokenKind[lexer.PAREN_R],
true,
); err != nil {
return variableDefinitions, err
} else {
for _, vdef := range vdefs {
if vdef != nil {
variableDefinitions = append(variableDefinitions, vdef.(*ast.VariableDefinition))
}
}
if err != nil {
return variableDefinitions, err
variableDefinitions = append(variableDefinitions, vdef.(*ast.VariableDefinition))
}
return variableDefinitions, nil
}
return variableDefinitions, nil
}
Expand All @@ -271,28 +269,28 @@ func parseVariableDefinitions(parser *Parser) ([]*ast.VariableDefinition, error)
* VariableDefinition : Variable : Type DefaultValue?
*/
func parseVariableDefinition(parser *Parser) (interface{}, error) {
var (
variable *ast.Variable
ttype ast.Type
err error
)
start := parser.Token.Start
variable, err := parseVariable(parser)
if err != nil {
if variable, err = parseVariable(parser); err != nil {
return nil, err
}
_, err = expect(parser, lexer.TokenKind[lexer.COLON])
if err != nil {
if _, err = expect(parser, lexer.TokenKind[lexer.COLON]); err != nil {
return nil, err
}
ttype, err := parseType(parser)
if err != nil {
if ttype, err = parseType(parser); err != nil {
return nil, err
}
var defaultValue ast.Value
if skp, err := skip(parser, lexer.TokenKind[lexer.EQUALS]); err != nil {
return nil, err
} else if skp {
dv, err := parseValueLiteral(parser, true)
if err != nil {
if defaultValue, err = parseValueLiteral(parser, true); err != nil {
return nil, err
}
defaultValue = dv
}
return ast.NewVariableDefinition(&ast.VariableDefinition{
Variable: variable,
Expand All @@ -306,13 +304,15 @@ func parseVariableDefinition(parser *Parser) (interface{}, error) {
* Variable : $ Name
*/
func parseVariable(parser *Parser) (*ast.Variable, error) {
var (
err error
name *ast.Name
)
start := parser.Token.Start
_, err := expect(parser, lexer.TokenKind[lexer.DOLLAR])
if err != nil {
if _, err = expect(parser, lexer.TokenKind[lexer.DOLLAR]); err != nil {
return nil, err
}
name, err := parseName(parser)
if err != nil {
if name, err = parseName(parser); err != nil {
return nil, err
}
return ast.NewVariable(&ast.Variable{
Expand All @@ -326,17 +326,16 @@ func parseVariable(parser *Parser) (*ast.Variable, error) {
*/
func parseSelectionSet(parser *Parser) (*ast.SelectionSet, error) {
start := parser.Token.Start
iSelections, err := reverse(parser,
selections := []ast.Selection{}
if iSelections, err := reverse(parser,
lexer.TokenKind[lexer.BRACE_L], parseSelection, lexer.TokenKind[lexer.BRACE_R],
true,
)
if err != nil {
); err != nil {
return nil, err
}
selections := []ast.Selection{}
for _, iSelection := range iSelections {
// type assert interface{} into Selection interface
selections = append(selections, iSelection.(ast.Selection))
} else {
for _, iSelection := range iSelections {
selections = append(selections, iSelection.(ast.Selection))
}
}

return ast.NewSelectionSet(&ast.SelectionSet{
Expand All @@ -353,8 +352,7 @@ func parseSelectionSet(parser *Parser) (*ast.SelectionSet, error) {
*/
func parseSelection(parser *Parser) (interface{}, error) {
if peek(parser, lexer.TokenKind[lexer.SPREAD]) {
r, err := parseFragment(parser)
return r, err
return parseFragment(parser)
}
return parseField(parser)
}
Expand Down Expand Up @@ -412,15 +410,15 @@ func parseField(parser *Parser) (*ast.Field, error) {
func parseArguments(parser *Parser) ([]*ast.Argument, error) {
arguments := []*ast.Argument{}
if peek(parser, lexer.TokenKind[lexer.PAREN_L]) {
iArguments, err := reverse(parser,
if iArguments, err := reverse(parser,
lexer.TokenKind[lexer.PAREN_L], parseArgument, lexer.TokenKind[lexer.PAREN_R],
true,
)
if err != nil {
); err != nil {
return arguments, err
}
for _, iArgument := range iArguments {
arguments = append(arguments, iArgument.(*ast.Argument))
} else {
for _, iArgument := range iArguments {
arguments = append(arguments, iArgument.(*ast.Argument))
}
}
}
return arguments, nil
Expand Down Expand Up @@ -462,9 +460,11 @@ func parseArgument(parser *Parser) (interface{}, error) {
* InlineFragment : ... TypeCondition? Directives? SelectionSet
*/
func parseFragment(parser *Parser) (interface{}, error) {
var (
err error
)
start := parser.Token.Start
_, err := expect(parser, lexer.TokenKind[lexer.SPREAD])
if err != nil {
if _, err = expect(parser, lexer.TokenKind[lexer.SPREAD]); err != nil {
return nil, err
}
if peek(parser, lexer.TokenKind[lexer.NAME]) && parser.Token.Value != "on" {
Expand Down Expand Up @@ -518,7 +518,7 @@ func parseFragment(parser *Parser) (interface{}, error) {
*/
func parseFragmentDefinition(parser *Parser) (ast.Node, error) {
start := parser.Token.Start
_, err := expectKeyWord(parser, "fragment")
_, err := expectKeyWord(parser, lexer.FRAGMENT)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -738,15 +738,12 @@ func parseObjectField(parser *Parser, isConst bool) (*ast.ObjectField, error) {
*/
func parseDirectives(parser *Parser) ([]*ast.Directive, error) {
directives := []*ast.Directive{}
for {
if !peek(parser, lexer.TokenKind[lexer.AT]) {
break
}
directive, err := parseDirective(parser)
if err != nil {
for peek(parser, lexer.TokenKind[lexer.AT]) {
if directive, err := parseDirective(parser); err != nil {
return directives, err
} else {
directives = append(directives, directive)
}
directives = append(directives, directive)
}
return directives, nil
}
Expand Down Expand Up @@ -944,7 +941,7 @@ func parseScalarTypeDefinition(parser *Parser) (ast.Node, error) {
if err != nil {
return nil, err
}
_, err = expectKeyWord(parser, "scalar")
_, err = expectKeyWord(parser, lexer.SCALAR)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -976,7 +973,7 @@ func parseObjectTypeDefinition(parser *Parser) (ast.Node, error) {
if err != nil {
return nil, err
}
_, err = expectKeyWord(parser, "type")
_, err = expectKeyWord(parser, lexer.TYPE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1161,7 +1158,7 @@ func parseInterfaceTypeDefinition(parser *Parser) (ast.Node, error) {
if err != nil {
return nil, err
}
_, err = expectKeyWord(parser, "interface")
_, err = expectKeyWord(parser, lexer.INTERFACE)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1204,7 +1201,7 @@ func parseUnionTypeDefinition(parser *Parser) (ast.Node, error) {
if err != nil {
return nil, err
}
_, err = expectKeyWord(parser, "union")
_, err = expectKeyWord(parser, lexer.UNION)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1264,7 +1261,7 @@ func parseEnumTypeDefinition(parser *Parser) (ast.Node, error) {
if err != nil {
return nil, err
}
_, err = expectKeyWord(parser, "enum")
_, err = expectKeyWord(parser, lexer.ENUM)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1335,7 +1332,7 @@ func parseInputObjectTypeDefinition(parser *Parser) (ast.Node, error) {
if err != nil {
return nil, err
}
_, err = expectKeyWord(parser, "input")
_, err = expectKeyWord(parser, lexer.INPUT)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1374,7 +1371,7 @@ func parseInputObjectTypeDefinition(parser *Parser) (ast.Node, error) {
*/
func parseTypeExtensionDefinition(parser *Parser) (ast.Node, error) {
start := parser.Token.Start
_, err := expectKeyWord(parser, "extend")
_, err := expectKeyWord(parser, lexer.EXTEND)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1405,7 +1402,7 @@ func parseDirectiveDefinition(parser *Parser) (ast.Node, error) {
if description, err = parseDescription(parser); err != nil {
return nil, err
}
if _, err = expectKeyWord(parser, "directive"); err != nil {
if _, err = expectKeyWord(parser, lexer.DIRECTIVE); err != nil {
return nil, err
}
if _, err = expect(parser, lexer.TokenKind[lexer.AT]); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion language/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"fmt"
"strings"

"reflect"

"github.com/graphql-go/graphql/language/ast"
"github.com/graphql-go/graphql/language/visitor"
"reflect"
)

func getMapValue(m map[string]interface{}, key string) interface{} {
Expand Down
Loading