doc/tutorial: add title with file names to code blocks (#2430)

This commit is contained in:
Ariel Mashraki
2022-03-26 18:49:04 +03:00
committed by GitHub
parent a89d1ec40f
commit cb7e0c1f1b
6 changed files with 27 additions and 27 deletions

View File

@@ -26,7 +26,7 @@ The Ent framework accepts external templates that can extend or override the def
code generator. In the template below, we generate 2 input types (`CreateTodoInput` and `UpdateTodoInput`) for the
GraphQL mutations, and add additional methods on the different builders to accept these objects as an input type.
```gotemplate
```gotemplate title="ent/template/mutation_input.tmpl"
{{ range $n := $.Nodes }}
{{ $input := print "Create" $n.Name "Input" }}
// {{ $input }} represents a mutation input for creating {{ plural $n.Name | lower }}.
@@ -113,7 +113,7 @@ go generate ./...
You may have noticed that Ent generated a new file `ent/mutation_input.go` with the following content:
```go
```go title="ent/template/mutation_input.go"
// Code generated by entc, DO NOT EDIT.
package ent
@@ -160,7 +160,7 @@ func (i *UpdateTodoInput) Mutate(m *TodoMutation) {
The new generated Go types are the GraphQL mutation types. Let's define them manually in the GraphQL schema and `gqlgen`
will map them automatically.
```graphql
```graphql title="todo.graphql"
# Define an input type for the mutation below.
# https://graphql.org/learn/schema/#input-types
#
@@ -207,7 +207,7 @@ go generate ./...
The result is as follows:
```go
```go title="todo.resolvers.go"
func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) {
panic(fmt.Errorf("not implemented"))
}
@@ -225,7 +225,7 @@ func (r *mutationResolver) UpdateTodos(ctx context.Context, ids []int, input ent
The `Set<F>` calls in the `CreateTodo` resolver are replaced with one call named `SetInput`:
```diff
```diff title="todo.resolvers.go"
func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) {
return ent.FromContext(ctx).Todo.
Create().
@@ -240,7 +240,7 @@ func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoI
The rest of the resolvers (`UpdateTodo` and `UpdateTodos`) will be implemented as follows:
```diff
```diff title="todo.resolvers.go"
func (r *mutationResolver) CreateTodo(ctx context.Context, input ent.CreateTodoInput) (*ent.Todo, error) {
return ent.FromContext(ctx).Todo.Create().SetInput(input).Save(ctx)
}