From 2015ef423de1fb87f43dd7869eaf6aa4358977af Mon Sep 17 00:00:00 2001 From: woonki Date: Tue, 10 Oct 2023 01:23:23 +0900 Subject: [PATCH] Fix property name as type (#45) --- .github/workflows/check-diff.yml | 8 ++++++++ CHANGELOG.md | 1 + Makefile | 6 +++--- lib/schema.go | 6 +++--- test/property_type/generated.graphql | 22 +++++++++++++++++++++ test/property_type/schema/Input.graphql | 4 ++++ test/property_type/schema/Interface.graphql | 4 ++++ 7 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 test/property_type/generated.graphql create mode 100644 test/property_type/schema/Input.graphql create mode 100644 test/property_type/schema/Interface.graphql diff --git a/.github/workflows/check-diff.yml b/.github/workflows/check-diff.yml index ad055f1..e556c65 100644 --- a/.github/workflows/check-diff.yml +++ b/.github/workflows/check-diff.yml @@ -20,6 +20,14 @@ jobs: uses: actions/setup-go@v3 with: go-version: ${{ matrix.go-version}} + + - name: Run make build + run: | + make build + + - name: Run make test + run: | + make test - name: Run make check-diff run: | diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6bf4c..b99e87b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## v0.2.11 - Fixed mis-used rune `[` instead of tokLBracket https://github.com/mununki/gqlmerge/pull/41 +- Fixed merge error when the property name as `type` https://github.com/mununki/gqlmerge/pull/45 ## v0.2.10 diff --git a/Makefile b/Makefile index 6abcae0..4bb9ecf 100644 --- a/Makefile +++ b/Makefile @@ -7,15 +7,15 @@ all: build test check-diff build: go build -test: build +test: @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; \ + ./gqlmerge $$dir $$output || exit 1; \ done -check-diff: build test +check-diff: @if git diff --exit-code --quiet -- '*.graphql'; then \ echo "Ok"; \ else \ diff --git a/lib/schema.go b/lib/schema.go index a30949f..3ed96d7 100644 --- a/lib/schema.go +++ b/lib/schema.go @@ -197,7 +197,7 @@ func (s *Schema) Parse(p *Parser) { fd.Filename = p.lex.filename fd.Line = p.lex.line fd.Column = p.lex.col - name, comments := p.lex.consumeIdent() + name, comments := p.lex.consumeIdent(tokInput, tokType) fd.Name = name.String() fd.Descriptions = comments @@ -291,7 +291,7 @@ func (s *Schema) Parse(p *Parser) { fd.Filename = p.lex.filename fd.Line = p.lex.line fd.Column = p.lex.col - name, comments := p.lex.consumeIdent() + name, comments := p.lex.consumeIdent(tokInput, tokType) fd.Name = name.String() fd.Descriptions = comments p.lex.consumeToken(tokColon) @@ -372,7 +372,7 @@ func (s *Schema) Parse(p *Parser) { fd.Filename = p.lex.filename fd.Line = p.lex.line fd.Column = p.lex.col - name, comments := p.lex.consumeIdent() + name, comments := p.lex.consumeIdent(tokInput, tokType) fd.Name = name.String() fd.Descriptions = comments diff --git a/test/property_type/generated.graphql b/test/property_type/generated.graphql new file mode 100644 index 0000000..4254040 --- /dev/null +++ b/test/property_type/generated.graphql @@ -0,0 +1,22 @@ +schema { + query: Query + mutation: Mutation + subscription: Subscription +} + +type SomePayload { + type: String! + someKey: String! +} + + + +interface I { + type: String! + input: String! +} + +input I { + type: String! + input: String! +} diff --git a/test/property_type/schema/Input.graphql b/test/property_type/schema/Input.graphql new file mode 100644 index 0000000..c80991a --- /dev/null +++ b/test/property_type/schema/Input.graphql @@ -0,0 +1,4 @@ +input I { + type: String! + input: String! +} \ No newline at end of file diff --git a/test/property_type/schema/Interface.graphql b/test/property_type/schema/Interface.graphql new file mode 100644 index 0000000..b45e089 --- /dev/null +++ b/test/property_type/schema/Interface.graphql @@ -0,0 +1,4 @@ +interface I { + type: String! + input: String! +} \ No newline at end of file