Skip to content

Commit

Permalink
Split examples into separate go module
Browse files Browse the repository at this point in the history
  • Loading branch information
lwc authored and mtibben committed Sep 13, 2021
1 parent 890f5f6 commit f93fb24
Show file tree
Hide file tree
Showing 13 changed files with 257 additions and 68 deletions.
1 change: 1 addition & 0 deletions .github/workflows/check-fmt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
set -euo pipefail

go fmt ./...
cd example && go fmt ./...
if [[ $(git --no-pager diff) ]] ; then
echo "you need to run "go fmt" and commit the changes"
git --no-pager diff
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/check-generate
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
set -euo pipefail

go generate ./...

cd example && go generate ./...
if [[ $(git --no-pager diff) ]] ; then
echo "you need to run "go generate ./..." and commit the changes"
git --no-pager diff
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go mod download
- run: go test -race ./...
- run: go mod download && go test -race ./...
- run: cd example && go mod download && go test -race ./...
6 changes: 3 additions & 3 deletions codegen/config/binder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestSlicePointerBinding(t *testing.T) {
panic(err)
}

require.Equal(t, ta.GO.String(), "[]*github.com/99designs/gqlgen/example/chat.Message")
require.Equal(t, ta.GO.String(), "[]*github.com/99designs/gqlgen/codegen/config/testdata/autobinding/chat.Message")
})

t.Run("with OmitSliceElementPointers", func(t *testing.T) {
Expand All @@ -41,14 +41,14 @@ func TestSlicePointerBinding(t *testing.T) {
panic(err)
}

require.Equal(t, ta.GO.String(), "[]github.com/99designs/gqlgen/example/chat.Message")
require.Equal(t, ta.GO.String(), "[]github.com/99designs/gqlgen/codegen/config/testdata/autobinding/chat.Message")
})
}

func createBinder(cfg Config) (*Binder, *ast.Schema) {
cfg.Models = TypeMap{
"Message": TypeMapEntry{
Model: []string{"github.com/99designs/gqlgen/example/chat.Message"},
Model: []string{"github.com/99designs/gqlgen/codegen/config/testdata/autobinding/chat.Message"},
},
}
cfg.Packages = &code.Packages{}
Expand Down
8 changes: 4 additions & 4 deletions codegen/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ func TestAutobinding(t *testing.T) {
cfg := Config{
Models: TypeMap{},
AutoBind: []string{
"github.com/99designs/gqlgen/example/chat",
"github.com/99designs/gqlgen/example/scalars/model",
"github.com/99designs/gqlgen/codegen/config/testdata/autobinding/chat",
"github.com/99designs/gqlgen/codegen/config/testdata/autobinding/scalars/model",
},
Packages: &code.Packages{},
}
Expand All @@ -187,8 +187,8 @@ func TestAutobinding(t *testing.T) {

require.NoError(t, cfg.autobind())

require.Equal(t, "github.com/99designs/gqlgen/example/scalars/model.Banned", cfg.Models["Banned"].Model[0])
require.Equal(t, "github.com/99designs/gqlgen/example/chat.Message", cfg.Models["Message"].Model[0])
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata/autobinding/scalars/model.Banned", cfg.Models["Banned"].Model[0])
require.Equal(t, "github.com/99designs/gqlgen/codegen/config/testdata/autobinding/chat.Message", cfg.Models["Message"].Model[0])
})

t.Run("with file path", func(t *testing.T) {
Expand Down
12 changes: 12 additions & 0 deletions codegen/config/testdata/autobinding/chat/message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package chat

import (
"time"
)

type Message struct {
ID string `json:"id"`
Text string `json:"text"`
CreatedBy string `json:"createdBy"`
CreatedAt time.Time `json:"createdAt"`
}
30 changes: 30 additions & 0 deletions codegen/config/testdata/autobinding/scalars/model/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package model

import (
"fmt"
"io"
"strings"
)

type Banned bool

func (b Banned) MarshalGQL(w io.Writer) {
if b {
w.Write([]byte("true"))
} else {
w.Write([]byte("false"))
}
}

func (b *Banned) UnmarshalGQL(v interface{}) error {
switch v := v.(type) {
case string:
*b = strings.ToLower(v) == "true"
return nil
case bool:
*b = Banned(v)
return nil
default:
return fmt.Errorf("%T is not a bool", v)
}
}
39 changes: 39 additions & 0 deletions example/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module github.com/99designs/gqlgen/example

go 1.17

replace github.com/99designs/gqlgen => ../

require (
github.com/99designs/gqlgen v0.0.0-00010101000000-000000000000
github.com/gorilla/websocket v1.4.2
github.com/mitchellh/mapstructure v1.4.1
github.com/opentracing/opentracing-go v1.2.0
github.com/rs/cors v1.8.0
github.com/stretchr/testify v1.7.0
github.com/vektah/dataloaden v0.3.0
github.com/vektah/gqlparser/v2 v2.2.0
sourcegraph.com/sourcegraph/appdash v0.0.0-20210831040556-ec77a7fbcadc
)

require (
github.com/agnivade/levenshtein v1.1.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/hashicorp/golang-lru v0.5.0 // indirect
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 // indirect
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546 // indirect
golang.org/x/mod v0.5.0 // indirect
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
sourcegraph.com/sourcegraph/appdash-data v0.0.0-20151005221446-73f23eafcf67 // indirect
)
Loading

0 comments on commit f93fb24

Please sign in to comment.