Skip to content

Commit

Permalink
Merge pull request #76 from jensneuse/bug/75-dropping-signature
Browse files Browse the repository at this point in the history
Parser dropping function signature
  • Loading branch information
jensneuse authored May 12, 2019
2 parents ed0d3c6 + 79bff9b commit 354708c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,9 @@ func (p *Printer) printOperation(operation document.OperationDefinition) {
p.printOperationType(operation.OperationType, hasName)
if hasName {
p.write(p.p.ByteSlice(operation.Name))
if len(operation.VariableDefinitions) > 0 {
p.printVariableDefinitions(operation.VariableDefinitions)
}
p.write(literal.SPACE)
}
if operation.DirectiveSet != -1 {
Expand Down Expand Up @@ -673,3 +676,32 @@ func (p *Printer) printListValue(ref int) {

p.write(literal.SQUAREBRACKETCLOSE)
}

func (p *Printer) printVariableDefinition(definition document.VariableDefinition) {
p.write(literal.DOLLAR)
p.write(p.p.ByteSlice(definition.Variable))
p.write(literal.COLON)
p.PrintType(definition.Type)
}

func (p *Printer) printVariableDefinitions(definitions []int) {

variableDefinitions := p.l.VariableDefinitionIterator(definitions)

p.write(literal.BRACKETOPEN)

prependSpaceBeforeNext := false

for variableDefinitions.Next() {
if prependSpaceBeforeNext {
p.write(literal.SPACE)
}

variable, _ := variableDefinitions.Value()
p.printVariableDefinition(variable)

prependSpaceBeforeNext = true
}

p.write(literal.BRACKETCLOSE)
}
6 changes: 6 additions & 0 deletions pkg/printer/printer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ func TestPrinter(t *testing.T) {
t.Run("multiple directive on field", func(t *testing.T) {
run("{foo @bar(baz:\"bat\") @foo2}")
})
t.Run("query with single argument", func(t *testing.T) {
run("query Anthem($name:String!) {name id}")
})
t.Run("query with multiple arguments", func(t *testing.T) {
run("query Anthem($name:String! $id:Int) {name id description}")
})
}

func TestPrinter_Regression(t *testing.T) {
Expand Down

0 comments on commit 354708c

Please sign in to comment.