作者:起飞吧和谐号况 | 来源:互联网 | 2023-09-23 00:06
Expected Behaviour
In the prev version of gqlgen everything was fine and worked great but after release, it does not work
Actual Behavior
When I run my code on local machine it works but when I start to build dockerfile it throws an error
1
| graphTry/server/server.go:22:68: cannot use graphTry.NewExecutableSchema(graphTry.Config literal) (type "github.com/USERNAME/user-name/vendor/github.com/99designs/gqlgen/graphql".ExecutableSchema) as type "github.com/99designs/gqlgen/graphql".ExecutableSchema in argument to handler.GraphQL: "github.com/Username/user-name/vendor/github.com/99designs/gqlgen/graphql".ExecutableSchema does not implement "github.com/99designs/gqlgen/graphql".ExecutableSchema (wrong type for Mutation method) have Mutation(context.Context, *"github.com/Username/user-name/vendor/github.com/vektah/gqlparser/ast".OperationDefinition) *"github.com/Username/user-name/vendor/github.com/99designs/gqlgen/graphql".Response want Mutation(context.Context, *"github.com/vektah/gqlparser/ast".OperationDefinition) *"github.com/99designs/gqlgen/graphql".Response |
my main file looks like this
` package main
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import (
//"Stack/overflow/finance/graphTry"
"github.com/Username/user-name/graphTry"
"net/http"
"os"
"github.com/99designs/gqlgen/handler"
"github.com/go-chi/chi"
"github.com/rs/cors"
)
const defaultPort = "8080"
func main() {
port := os.Getenv("PORT")
if port == "" {
port = defaultPort
}
router := chi.NewRouter()
router.Use(cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowCredentials: true,
Debug: true,
}).Handler)
router.Handle("/", handler.Playground("graphtry", "/query"))
router.Handle("/query",
handler.GraphQL(graphTry.NewExecutableSchema(graphTry.Config{Resolvers:
&graphTry.Resolver{}})),
)
err := http.ListenAndServe(":8080", router)
if err != nil {
panic(err)
}
}` |
and my dockerfile
`FROM golang:1.10.2-alpine3.7 AS build
RUN apk --no-cache add gcc g++ make ca-certificates
WORKDIR /home/username/go/src/Stack/overflow/finance
RUN ls
RUN pwd
COPY . .
RUN pwd
RUN apk update && apk add git
RUN go get github.com/golang/protobuf/jsonpb
RUN go get github.com/golang/protobuf/proto
RUN go get github.com/lib/pq
RUN go get github.com/twitchtv/twirp
RUN go get github.com/twitchtv/twirp/ctxsetters
RUN go get github.com/99designs/gqlgen/graphql
RUN go get github.com/99designs/gqlgen/graphql/introspection
RUN go get github.com/vektah/gqlparser
RUN go get github.com/vektah/gqlparser/ast
RUN go get github.com/99designs/gqlgen/cmd
RUN go get github.com/99designs/gqlgen/handler
RUN go get github.com/Username/user-name/server
RUN go get github.com/Username/user-name/rpc/finance
RUN go get github.com/Username/user-name/graphTry
RUN go get github.com/go-chi/chi
RUN go get github.com/rs/cors
RUN go get github.com/vektah/gqlparser
RUN go build -o /go/bin/stackexample ./graphTry/server/server.go
FROM alpine:3.7 as final
WORKDIR /usr/bin
COPY --from=build /go/bin .
EXPOSE 8080
CMD ["./stackexample"]`
Minimal graphql.schema and models to reproduce
该提问来源于开源项目:99designs/gqlgen
If it helps anyone, I had to change the version to 0.10.1 (in mod file) and the errors are gone