howtographql
howtographql copied to clipboard
Go Tutorial it's broken
Hi!
Multiple Issues: 1.
go run github.com/99designs/gqlgen init
This command will create a completely different code from the one used in the tutorial.
Created:
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{Resolvers: &graph.Resolver{}}))
http.Handle("/", playground.Handler("GraphQL playground", "/query"))
http.Handle("/query", srv)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, nil))
Expected: https://www.howtographql.com/graphql-go/6-authentication/
import (
hackernews "github.com/glyphack/go-graphql-hackernews"
)
(...)
router := chi.NewRouter()
server := handler.NewDefaultServer(hackernews.NewExecutableSchema(hackernews.Config{Resolvers: &hackernews.Resolver{}}))
router.Handle("/", playground.Handler("GraphQL playground", "/query"))
router.Handle("/query", server)
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, router))
This issue will allow us to do the tutorial up to Authentication.
On the authentication, we need to add a middleware to the server and the code will not work.
At this moment we will try to change the code to the code shown on the examples (the expected version).
But the problem is that:
The import: hackernews "github.com/glyphack/go-graphql-hackernews" used on the server will redirect to: "https://github.com/Glyphack/graphql-golang" and this project defines its modules as github.com/glyphack/graphlq-golang.
We have a small typo: graphlq vs graphql.
This will lead to major frustration trying to deal with broken packages instead of focusing on learning GraphQl.
I tried to update this guide here but we are short on maintainers. I'm not sure if it's possible to keep this fully updated. Maybe you can check this PR here, and also use the Glyphack/graphql-golang it is updated more regularly.