Skip to content

Commit

Permalink
Merge branch 'ysugimoto:master' into fix/issue-61
Browse files Browse the repository at this point in the history
  • Loading branch information
qwerty-v authored May 5, 2024
2 parents 10b8008 + ca05fe6 commit e683769
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 94 deletions.
60 changes: 0 additions & 60 deletions .circleci/config.yml

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Build application

on:
push:
branches:
- "*"
tags-ignore:
- "v*.*.*"

env:
PROTOC_VERSION: 3.14.0
GO_VERSION: 1.21.1

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup protobuf
run: |
PROTOC_ZIP=protoc-${{ env.PROTOC_VERSION }}-linux-x86_64.zip
curl -OL https://github.com/google/protobuf/releases/download/v${{ env.PROTOC_VERSION }}/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local/protoc
sudo chmod +xr -R /usr/local/protoc
sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin
sudo ln -s /usr/local/protoc/include/google /usr/local/include/google
- name: Lint programs
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
skip-pkg-cache: true
skip-build-cache: true
skip-go-installation: true
- name: Build app
run: |
go install google.golang.org/protobuf/cmd/[email protected]
make all tag=ci
58 changes: 58 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Publish application

on:
push:
tags:
- "v*.*.*"

env:
PROTOC_VERSION: 3.14.0
GO_VERSION: 1.21.1

jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup go
uses: actions/setup-go@v4
with:
go-version: ${{ env.GO_VERSION }}
- name: Setup protobuf
run: |
PROTOC_ZIP=protoc-${{ env.PROTOC_VERSION }}-linux-x86_64.zip
curl -OL https://github.com/google/protobuf/releases/download/v${{ env.PROTOC_VERSION }}/$PROTOC_ZIP
sudo unzip -o $PROTOC_ZIP -d /usr/local/protoc
sudo chmod +xr -R /usr/local/protoc
sudo ln -s /usr/local/protoc/bin/protoc /usr/local/bin
sudo ln -s /usr/local/protoc/include/google /usr/local/include/google
- name: Lint programs
uses: golangci/golangci-lint-action@v3
with:
version: v1.54
skip-pkg-cache: true
skip-build-cache: true
skip-go-installation: true
- name: Set version
id: version
run: |
VERSION=$(echo ${{ github.ref }} | sed -e "s#refs/tags/##g")
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Build app
run: |
go install google.golang.org/protobuf/cmd/[email protected]
make all tag=${{ steps.version.outputs.version }}
- name: Release app
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/')
with:
files: |
dist/protoc-gen-graphql.darwin
dist/protoc-gen-graphql.darwin.arm64
dist/protoc-gen-graphql.linux
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}


11 changes: 1 addition & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ run:

issues:
exclude-rules:
## Add file patters to exclude linter
## Add file patterns to exclude linter
- path: grpc\/main\.go
linters:
- gomnd
Expand All @@ -26,11 +26,7 @@ linters:
- staticcheck
- unused
- gosimple
- structcheck
- varcheck
- ineffassign
- interfacer
- deadcode
- dogsled
- dupl
- funlen
Expand All @@ -41,7 +37,6 @@ linters:
- gofmt
- gomnd
- lll
- maligned
- misspell
- whitespace
- unparam
Expand Down Expand Up @@ -137,16 +132,12 @@ linters-settings:
simplify: true
golint:
min-confidence: 0.8
govet:
check-shadowing: true
gomnd:
settings:
mnd:
checks: argument,assign,operation,return
lll:
line-length: 120
maligned:
suggest-new: true
misspell:
locale: US
ignore-words:
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ clean:

all: clean build
cd ${GRAPHQL_CMD} && GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${VERSION}" -o ../dist/${GRAPHQL_CMD}.darwin
cd ${GRAPHQL_CMD} && GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${VERSION}" -o ../dist/${GRAPHQL_CMD}.darwin.arm64
cd ${GRAPHQL_CMD} && GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${VERSION}" -o ../dist/${GRAPHQL_CMD}.linux
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# grpc-graphql-gateway

[![CircleCI](https://circleci.com/gh/ysugimoto/grpc-graphql-gateway/tree/master.svg?style=svg)](https://circleci.com/gh/ysugimoto/grpc-graphql-gateway/tree/master)

`grpc-graphql-gateway` is a protoc plugin that generates graphql execution code from Protocol Buffers.

![image](https://raw.githubusercontent.com/ysugimoto/grpc-graphql-gateway/master/misc/grpc-graphql-gateway.png)
Expand Down
14 changes: 11 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
module github.com/ysugimoto/grpc-graphql-gateway

go 1.15
go 1.21

require (
github.com/golang/protobuf v1.4.0
github.com/graphql-go/graphql v0.7.8
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
google.golang.org/grpc v1.27.0
google.golang.org/protobuf v1.22.0
)

require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.0.0-20190311183353-d8887717615a // indirect
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae // indirect
golang.org/x/text v0.3.0 // indirect
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ github.com/graphql-go/graphql v0.7.8 h1:769CR/2JNAhLG9+aa8pfLkKdR0H+r5lsQqling5W
github.com/graphql-go/graphql v0.7.8/go.mod h1:k6yrAYQaSP59DC5UVxbgxESlmVyojThKdORUqGDGmrI=
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 h1:VHgatEHNcBFEB7inlalqfNqw65aNkM1lGX2yt3NmbS8=
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334/go.mod h1:SK73tn/9oHe+/Y0h39VT4UCxmurVJkR5NA7kMEAOgSE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
Expand Down
4 changes: 2 additions & 2 deletions graphql/graphql.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions protoc-gen-graphql/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"bytes"
"errors"
"fmt"
"io"
"os"
"sort"

"go/format"
"io/ioutil"
"text/template"

// nolint: staticcheck
Expand Down Expand Up @@ -53,7 +53,7 @@ func New(files []*spec.File, args *spec.Params) *Generator {
}
}

w := ioutil.Discard
w := io.Discard
if args.Verbose {
w = os.Stderr
}
Expand Down Expand Up @@ -101,6 +101,10 @@ func (g *Generator) Generate(tmpl string, fs []string) ([]*plugin.CodeGeneratorR
return outFiles, nil
}

func isDependedGoogleEmptyMessage(m *spec.Message, pkg string) bool {
return m.IsDepended(spec.DependTypeMessage, pkg) && spec.IsGooglePackage(m) && m.Name() == "Empty"
}

// nolint: gocognit, funlen, gocyclo
func (g *Generator) generateFile(file *spec.File, tmpl string, services []*spec.Service) (
*plugin.CodeGeneratorResponse_File,
Expand All @@ -114,6 +118,11 @@ func (g *Generator) generateFile(file *spec.File, tmpl string, services []*spec.
for _, m := range g.messages {
// skip empty field message, otherwise graphql-go raise error
if len(m.Fields()) == 0 {
// although true, Google's empty message has no fields,
// ptypes package define a dummy field, that way no errors raised
if isDependedGoogleEmptyMessage(m, file.Package()) {
packages = append(packages, spec.NewGooglePackage(m))
}
continue
}
if m.IsDepended(spec.DependTypeMessage, file.Package()) {
Expand Down Expand Up @@ -238,7 +247,7 @@ func (g *Generator) generateFile(file *spec.File, tmpl string, services []*spec.

out, err := format.Source(buf.Bytes())
if err != nil {
ioutil.WriteFile("/tmp/"+root.Name+".go", buf.Bytes(), 0666) // nolint: errcheck
os.WriteFile("/tmp/"+root.Name+".go", buf.Bytes(), 0o666) // nolint: gomnd,errcheck
return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-graphql/spec/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewEnum(
for i, v := range d.GetValue() {
ps := make([]int, len(paths))
copy(ps, paths)
e.values = append(e.values, NewEnumValue(v, f, append(ps, 2, i)...))
e.values = append(e.values, NewEnumValue(v, f, append(ps, 2, i)...)) // nolint: gomnd
}
return e
}
Expand Down
10 changes: 5 additions & 5 deletions protoc-gen-graphql/spec/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func NewFile(
isCamel: isCamel,
}
for i, s := range d.GetService() {
f.services = append(f.services, NewService(s, f, 6, i))
f.services = append(f.services, NewService(s, f, 6, i)) // nolint: gomnd
}
for i, m := range d.GetMessageType() {
f.messages = append(f.messages, f.messagesRecursive(m, []string{}, 4, i)...)
f.messages = append(f.messages, f.messagesRecursive(m, []string{}, 4, i)...) // nolint: gomnd
}
for i, e := range d.GetEnumType() {
f.enums = append(f.enums, NewEnum(e, f, []string{}, 5, i))
f.enums = append(f.enums, NewEnum(e, f, []string{}, 5, i)) // nolint: gomnd
}
return f
}
Expand Down Expand Up @@ -80,15 +80,15 @@ func (f *File) messagesRecursive(d *descriptor.DescriptorProto, prefix []string,
for i, e := range d.GetEnumType() {
p := make([]int, len(paths))
copy(p, paths)
f.enums = append(f.enums, NewEnum(e, f, prefix, append(p, 5, i)...))
f.enums = append(f.enums, NewEnum(e, f, prefix, append(p, 5, i)...)) // nolint: gomnd
}

for i, m := range d.GetNestedType() {
p := make([]int, len(paths))
copy(p, paths)
messages = append(
messages,
f.messagesRecursive(m, prefix, append(p, 3, i)...)...,
f.messagesRecursive(m, prefix, append(p, 3, i)...)..., // nolint: gomnd
)
}
return messages
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-graphql/spec/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func NewMessage(
for i, field := range d.GetField() {
ps := make([]int, len(paths))
copy(ps, paths)
ff := NewField(field, f, isCamel, append(ps, 2, i)...)
ff := NewField(field, f, isCamel, append(ps, 2, i)...) // nolint: gomnd
if !ff.IsOmit() {
m.fields = append(m.fields, ff)
}
Expand Down
1 change: 0 additions & 1 deletion protoc-gen-graphql/spec/mutation.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ func (m *Mutation) OutputName() string {
return typeName
}

//
func (m *Mutation) InputType() string {
if m.Method.GoPackage() != m.Input.GoPackage() {
return m.Input.StructName(false)
Expand Down
2 changes: 1 addition & 1 deletion protoc-gen-graphql/spec/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func NewParams(p string) (*Params, error) {
}

for _, v := range strings.Split(p, ",") {
kv := strings.SplitN(v, "=", 2)
kv := strings.SplitN(v, "=", 2) // nolint: gomnd
switch kv[0] {
case "verbose":
params.Verbose = true
Expand Down
Loading

0 comments on commit e683769

Please sign in to comment.