You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I try integrating it inside the main function I get r.Middleware undefined (type *httprouter.Router has no field or method Middleware)compilerMissingFieldOrMethod
package main
import (
"gographql-server/graph"
"gographql-server/graph/generated"
"gographql-server/middlewares"
"log"
"net/http"
"os"
"github.com/99designs/gqlgen/graphql/handler"
"github.com/99designs/gqlgen/graphql/playground"
"github.com/julienschmidt/httprouter"
)
const defaultPort = "8080"
func PlaygroundHandler() httprouter.Handle {
h := playground.Handler("GraphQL", "/query")
return func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
h.ServeHTTP(w, req)
}
}
func GraphqlHandler() httprouter.Handle {
h := handler.NewDefaultServer(generated.NewExecutableSchema(generated.Config{Resolvers: &graph.Resolver{}}))
return func(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
h.ServeHTTP(w, req)
}
}
func main() {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
r := httprouter.New()
r.POST("/query", GraphqlHandler())
r.GET("/", PlaygroundHandler())
r.Middleware(middlewares.AuthMiddleware())
log.Printf("connect to http://localhost:%s/ for GraphQL playground", port)
log.Fatal(http.ListenAndServe(":"+port, r))
}
The text was updated successfully, but these errors were encountered:
I have this Custom authenitifcation middleware
When I try integrating it inside the main function I get r.Middleware undefined (type *httprouter.Router has no field or method Middleware)compilerMissingFieldOrMethod
The text was updated successfully, but these errors were encountered: