Skip to content

Commit

Permalink
Merge pull request #172 from vvakame/feat-newconfig
Browse files Browse the repository at this point in the history
switch to .gqlgen.yml
  • Loading branch information
vektah authored Jul 8, 2018
2 parents 325c45a + c7ce1cb commit 57b8279
Show file tree
Hide file tree
Showing 18 changed files with 77 additions and 51 deletions.
25 changes: 17 additions & 8 deletions docs/content/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,21 @@ type Todo struct {

So we have our schema and our models. now we need to link them up:

`graph/types.json`
```json
{
"User": "github.com/vektah/gqlgen-tutorials/gettingstarted/graph.User",
"Todo": "github.com/vektah/gqlgen-tutorials/gettingstarted/graph.Todo"
}
`graph/.gqlgen.yml`
```yaml
schema: ../schema.graphql
exec:
# filename: generated.go
# package:
model:
# filename: models_gen.go
# package:

models:
Todo:
model: github.com/vektah/gqlgen-tutorials/gettingstarted/graph.Todo
User:
model: github.com/vektah/gqlgen-tutorials/gettingstarted/graph.User
```
This simply says, `User` in schema is backed by `graph.User` in go.

Expand All @@ -104,7 +113,7 @@ Lets generate the server now:
```bash
mkdir graph
cd graph
gqlgen -typemap types.json -schema ../schema.graphql
gqlgen
```

gqlgen should have created two new files `generated.go` and `models_gen.go`. If we take a peek in both we can see what the server has generated:
Expand Down Expand Up @@ -258,7 +267,7 @@ go get github.com/vektah/gorunpkg

Now at the top of our graph.go:
```go
//go:generate gorunpkg gqlgen -typemap types.json -schema ../schema.graphql
//go:generate gorunpkg gqlgen

package graph
```
Expand Down
20 changes: 10 additions & 10 deletions docs/content/reference/scalars.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ func (y YesNo) MarshalGQL(w io.Writer) {
}
```

and then in types.json point to the name without the Marshal|Unmarshal in front:
```json
{
"YesNo": "github.com/me/mypkg.YesNo"
}
and then in .gqlgen.yml point to the name without the Marshal|Unmarshal in front:
```yaml
models:
YesNo:
model: github.com/me/mypkg.YesNo
```
Expand Down Expand Up @@ -96,11 +96,11 @@ func UnmarshalMyCustomBooleanScalar(v interface{}) (bool, error) {
}
```

and then in types.json point to the name without the Marshal|Unmarshal in front:
```json
{
"MyCustomBooleanScalar": "github.com/me/mypkg.MyCustomBooleanScalar"
}
and then in .gqlgen.yml point to the name without the Marshal|Unmarshal in front:
```yaml
models:
MyCustomBooleanScalar:
model: github.com/me/mypkg.MyCustomBooleanScalar
```
see the [example/scalars](https://github.com/vektah/gqlgen/tree/master/example/scalars) package for more examples.
3 changes: 3 additions & 0 deletions example/chat/.gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
models:
Chatroom:
model: github.com/vektah/gqlgen/example/chat.Chatroom
2 changes: 1 addition & 1 deletion example/chat/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/vektah/gqlgen -typemap types.json -out generated.go
//go:generate gorunpkg github.com/vektah/gqlgen

package chat

Expand Down
3 changes: 0 additions & 3 deletions example/chat/types.json

This file was deleted.

5 changes: 5 additions & 0 deletions example/dataloader/.gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
models:
Order:
model: github.com/vektah/gqlgen/example/dataloader.Order
Customer:
model: github.com/vektah/gqlgen/example/dataloader.Customer
2 changes: 1 addition & 1 deletion example/dataloader/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/vektah/gqlgen -out generated.go -typemap types.json
//go:generate gorunpkg github.com/vektah/gqlgen

package dataloader

Expand Down
4 changes: 0 additions & 4 deletions example/dataloader/types.json

This file was deleted.

13 changes: 13 additions & 0 deletions example/scalars/.gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
models:
User:
model: github.com/vektah/gqlgen/example/scalars.User
Timestamp:
model: github.com/vektah/gqlgen/example/scalars.Timestamp
SearchArgs:
model: github.com/vektah/gqlgen/example/scalars.SearchArgs
Point:
model: github.com/vektah/gqlgen/example/scalars.Point
ID:
model: github.com/vektah/gqlgen/example/scalars.ID
Tier:
model: github.com/vektah/gqlgen/example/scalars.Tier
2 changes: 1 addition & 1 deletion example/scalars/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (p Point) MarshalGQL(w io.Writer) {
fmt.Fprintf(w, `"%d,%d"`, p.X, p.Y)
}

// if the type referenced in types.json is a function that returns a marshaller we can use it to encode and decode
// if the type referenced in .gqlgen.yml is a function that returns a marshaller we can use it to encode and decode
// onto any existing go type.
func MarshalTimestamp(t time.Time) graphql.Marshaler {
return graphql.WriterFunc(func(w io.Writer) {
Expand Down
2 changes: 1 addition & 1 deletion example/scalars/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/vektah/gqlgen -typemap types.json -out generated.go
//go:generate gorunpkg github.com/vektah/gqlgen

package scalars

Expand Down
8 changes: 0 additions & 8 deletions example/scalars/types.json

This file was deleted.

2 changes: 1 addition & 1 deletion example/selection/selection.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/vektah/gqlgen -out generated.go
//go:generate gorunpkg github.com/vektah/gqlgen

package selection

Expand Down
15 changes: 15 additions & 0 deletions example/starwars/.gqlgen.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
models:
Droid:
model: github.com/vektah/gqlgen/example/starwars.Droid
FriendsConnection:
model: github.com/vektah/gqlgen/example/starwars.FriendsConnection
FriendsEdge:
model: github.com/vektah/gqlgen/example/starwars.FriendsEdge
Human:
model: github.com/vektah/gqlgen/example/starwars.Human
Review:
model: github.com/vektah/gqlgen/example/starwars.Review
ReviewInput:
model: github.com/vektah/gqlgen/example/starwars.Review
Starship:
model: github.com/vektah/gqlgen/example/starwars.Starship
2 changes: 1 addition & 1 deletion example/starwars/resolvers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/vektah/gqlgen -typemap types.json -out generated.go
//go:generate gorunpkg github.com/vektah/gqlgen

package starwars

Expand Down
9 changes: 0 additions & 9 deletions example/starwars/types.json

This file was deleted.

9 changes: 7 additions & 2 deletions test/.gqlgen.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
schema: schema.graphql
output: generated.go
modeloutput: models/generated.go

exec:
filename: generated.go
# package:
model:
filename: models/generated.go
# package:

models:
Element:
Expand Down
2 changes: 1 addition & 1 deletion test/resolvers_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate gorunpkg github.com/vektah/gqlgen -models models/generated.go
//go:generate gorunpkg github.com/vektah/gqlgen

package test

Expand Down

0 comments on commit 57b8279

Please sign in to comment.