99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.86k stars 1.15k forks source link

When I try to build my project inside docker it throws an error #459

Closed AkezhanOb1 closed 5 years ago

AkezhanOb1 commented 5 years ago

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 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

 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

vektah commented 5 years ago
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) 

This happens when you mix vendored and non vendored code, you've got to go all in on vendor, or all in on go get (and make sure you prune any vendor directories you might have)

WLun001 commented 4 years ago

@vektah @AkezhanOb1, I faced the same problem, How can i fix it?

it only happened after i go get -u ./..., and only happened on gqlgen version: v0.11.2

api/graphql/generated.go:24:9: cannot use &executableSchema literal (type *executableSchema) as type graphql.ExecutableSchema in return argument:
    *executableSchema does not implement graphql.ExecutableSchema (missing Exec method)
api/graphql/generated.go:583:11: ec.RequestMiddleware undefined (type executionContext has no field or method RequestMiddleware)
api/graphql/generated.go:592:17: ec.Errors undefined (type executionContext has no field or method Errors)
api/graphql/generated.go:593:17: ec.Extensions undefined (type executionContext has no field or method Extensions)
api/graphql/generated.go:600:11: ec.RequestMiddleware undefined (type executionContext has no field or method RequestMiddleware)
api/graphql/generated.go:609:17: ec.Errors undefined (type executionContext has no field or method Errors)
api/graphql/generated.go:610:17: ec.Extensions undefined (type executionContext has no field or method Extensions)
api/graphql/generated.go:615:24: cannot use graphql.OneShot(graphql.ErrorResponse(ctx, "subscriptions are not supported")) (type graphql.ResponseHandler) as type func() *graphql.Response in return argument
api/graphql/generated.go:627:33: cannot use parsedSchema (type *"github.com/vektah/gqlparser/ast".Schema) as type *"github.com/vektah/gqlparser/v2/ast".Schema in argument to introspection.WrapSchema
api/graphql/generated.go:634:38: cannot use parsedSchema (type *"github.com/vektah/gqlparser/ast".Schema) as type *"github.com/vektah/gqlparser/v2/ast".Schema in argument to introspection.WrapTypeFromDef
api/graphql/generated.go:634:38: too many errors
cghorai commented 4 years ago

Facing the exact same problem after doing an update! Any way fix this?

cghorai commented 4 years ago

If it helps anyone, I had to change the version to 0.10.1 (in mod file) and the errors are gone

tylerrowsell commented 3 years ago

@WLun001 , @cghorai were able to solve without locking to 0.10.1?