The following command failed. This happens when you implement the code according to Implement the resolvers
โฏ go run server.go
graph/schema.resolvers.go:18:36: not enough arguments in call to "crypto/rand".Int
have ()
want (io.Reader, *big.Int)
graph/schema.resolvers.go:18:36: multiple-value "crypto/rand".Int() in single-value context
The server is successfully started.
graphql.schema and models
# GraphQL schema example
#
# https://gqlgen.com/getting-started/
type Todo {
id: ID!
text: String!
done: Boolean!
user: User!
}
type User {
id: ID!
name: String!
}
type Query {
todos: [Todo!]!
}
input NewTodo {
text: String!
userId: String!
}
type Mutation {
createTodo(input: NewTodo!): Todo!
}
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.
package model
type NewTodo struct {
Text string `json:"text"`
UserID string `json:"userId"`
}
type Todo struct {
ID string `json:"id"`
Text string `json:"text"`
Done bool `json:"done"`
User *User `json:"user"`
}
type User struct {
ID string `json:"id"`
Name string `json:"name"`
}
gqlgen version: v0.11.3go version: go version go1.13.8 linux/amd64This patch makes it boot up.
diff --git a/server-next/graph/schema.resolvers.go b/server-next/graph/schema.resolvers.go
index d14d5d1..ffa99c8 100644
--- a/server-next/graph/schema.resolvers.go
+++ b/server-next/graph/schema.resolvers.go
@@ -7,15 +7,18 @@ import (
"context"
"crypto/rand"
"fmt"
+ "math/big"
"github.com/ksoda/todo-app/graph/generated"
"github.com/ksoda/todo-app/graph/model"
)
func (r *mutationResolver) CreateTodo(ctx context.Context, input model.NewTodo) (*model.Todo, error) {
+ rand, _ := rand.Int(rand.Reader, big.NewInt(100))
todo := &model.Todo{
+
Text: input.Text,
- ID: fmt.Sprintf("T%d", rand.Int()),
+ ID: fmt.Sprintf("T%d", rand),
User: &model.User{ID: input.UserID, Name: "user " + input.UserID},
}
r.todos = append(r.todos, todo)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Simply import "math/rand" instead of "crypto/rand"
Most helpful comment
This patch makes it boot up.