From 839a842fa60b47c49a0781cb09d45b50eb7a5a24 Mon Sep 17 00:00:00 2001 From: Lai Date: Wed, 11 May 2022 20:00:17 +0800 Subject: [PATCH] Update getting-started.md Fix getting-started missing fields resolver config --- docs/content/getting-started.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/content/getting-started.md b/docs/content/getting-started.md index 300463bfb5c..5e89ef4ad63 100644 --- a/docs/content/getting-started.md +++ b/docs/content/getting-started.md @@ -202,6 +202,31 @@ autobind: - "github.com/[username]/gqlgen-todos/graph/model" ``` +And add `Todo` fields resolver config in `gqlgen.yml` to generate resolver for `user` field +```yml +# This section declares type mapping between the GraphQL and go type systems +# +# The first line in each type will be used as defaults for resolver arguments and +# modelgen, the others will be allowed when binding to fields. Configure them to +# your liking +models: + ID: + model: + - github.com/99designs/gqlgen/graphql.ID + - github.com/99designs/gqlgen/graphql.Int + - github.com/99designs/gqlgen/graphql.Int64 + - github.com/99designs/gqlgen/graphql.Int32 + Int: + model: + - github.com/99designs/gqlgen/graphql.Int + - github.com/99designs/gqlgen/graphql.Int64 + - github.com/99designs/gqlgen/graphql.Int32 + Todo: + fields: + user: + resolver: true +``` + Next, create a new file called `graph/model/todo.go` ```go @@ -211,6 +236,7 @@ type Todo struct { ID string `json:"id"` Text string `json:"text"` Done bool `json:"done"` + UserID string `json:"userId"` User *User `json:"user"` } ```