Skip to content

Commit

Permalink
Fix parse error when argument name has input (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
mununki authored Oct 4, 2023
1 parent 6adfe61 commit 1db0be1
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ gqlmerge
.idea

demo/demo.yml
!test/*.graphql
!test/**/*.graphql
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SHELL = /bin/bash

.PHONY: all build test

all: build test

build:
go build

test: build
@for dir in $(shell find test -type d -name schema); do \
basedir=`dirname $$dir`; \
output="$$basedir/generated.graphql"; \
echo "Merging $$dir into $$output..."; \
./gqlmerge $$dir $$output; \
done
13 changes: 11 additions & 2 deletions lib/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,15 +460,24 @@ func (l *lexer) consumeToken(expected tokenType) {
l.skipSpace()
}

func (l *lexer) consumeIdent() (*token, *[]string) {
func (l *lexer) consumeIdent(includings ...tokenType) (*token, *[]string) {
comments := []string{}
for {
tok := l.next()
if tok.typ == tokString || tok.typ == tokSingleLineComment || tok.typ == tokBlockString {
comments = append(comments, tok.String())
continue
}
if tok.typ != tokIdent {

isIncluded := false
for _, incl := range includings {
if tok.typ == incl {
isIncluded = true
break
}
}

if tok.typ != tokIdent && !isIncluded {
errorf(`%s:%d:%d: unexpected "%s"`, l.filename, l.line, l.col, tok.String())
}
l.skipSpace()
Expand Down
2 changes: 1 addition & 1 deletion lib/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (p *Parser) parseArgs() []*Arg {
p.lex.consumeToken(tokLParen)
for p.lex.peek() != ')' {
arg := Arg{}
name, comments := p.lex.consumeIdent()
name, comments := p.lex.consumeIdent(tokInput, tokType)
arg.Name = name.String()
arg.Descriptions = comments
p.lex.consumeToken(tokColon)
Expand Down
8 changes: 8 additions & 0 deletions lib/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ func TestParsing(t *testing.T) {
scalar DateTime # TEST
union Response = Success | Failure
input CreateLogInput {
text: String!
}
type Mutation {
createLogKo(input: CreateLogInput!): String!
}
`

s := Schema{}
Expand Down
17 changes: 17 additions & 0 deletions test/arg_input/generated.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
schema {
query: Query
mutation: Mutation
subscription: Subscription
}

type Mutation {
createLogKo(input: CreateLogInput!): String!
createLogOk(inputLog: CreateLogInput!): String!
}




input CreateLogInput {
text: String!
}
File renamed without changes.
File renamed without changes.
9 changes: 0 additions & 9 deletions test/generated.graphql → test/basic/generated.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ type User implements Node & Owner {
avatar: Url
}

type Mutation {
createLogKo(inputx: CreateLogInput!): String!
createLogOk(inputLog: CreateLogInput!): String!
}

type UserResponse {
ok: Boolean!
error: String
Expand Down Expand Up @@ -76,7 +71,3 @@ input CreateChatInput {
" post_id "
postId: ID!
}

input CreateLogInput {
text: String!
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 1db0be1

Please sign in to comment.