Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vvakame committed Jul 6, 2018
1 parent 4294815 commit c7ce1cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 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.
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

0 comments on commit c7ce1cb

Please sign in to comment.