Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated models do not implement user defined interfaces #716

Closed
samlitowitz opened this issue May 17, 2019 · 4 comments
Closed

Generated models do not implement user defined interfaces #716

samlitowitz opened this issue May 17, 2019 · 4 comments
Labels

Comments

@samlitowitz
Copy link

What happened?

Generated models do not fulfill user defined interfaces provided through models configuration.

// models/generated.go
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.

package models

type MyObect struct {
	ID string `json:"id"`
}

func (MyObect) IsMyInterface() {}

What did you expect?

An error preventing me from doing this, OR the generated models need to fulfill the user defined interface, i.e.

// models/generated.go
// Code generated by github.com/99designs/gqlgen, DO NOT EDIT.

package models

type MyObect struct {
	ID string `json:"id"`
}

func (MyObect) Baz() {}

Minimal graphql.schema and models to reproduce

# .gqlgen.yml
exec:
  filename: generated/exec.go
model:
  filename: models/generated.go

models:
  MyInterface:
    model: github.com/99designs/gqlgen/example/interface_failure/models.MyInterface
# schema.graphql
interface MyInterface  {
    id: ID!
}

type MyObect implements MyInterface {
    id: ID!
}

type Query {
    myObjects: MyObect!
}
// models/my_interface.go
package models

type MyInterface interface {
	Baz()
}

versions

  • gqlgen version? dev, from master with test case added to the example/ directory
  • go version? go version go1.12.4 linux/amd64
  • dep or go modules? master branch go.mod
@hh
Copy link
Contributor

hh commented May 19, 2019

I also found this working through https://gqlgen.com/getting-started/

See https://github.com/ii/org/blob/master/research/gqlgen.org#errors

Where I was writing up an org file for it and ran into:

-*- mode: compilation; default-directory: "~/gqlgen-todos/" -*-
Compilation started at Sun May 19 07:11:45

go run server/server.go 
# github.com/hh/gqlgen-todos
./resolver.go:17:24: cannot use &queryResolver literal (type *queryResolver) as type QueryResolver in return argument:
	*queryResolver does not implement QueryResolver (wrong type for Todos method)
		have Todos(context.Context) ([]Todo, error)
		want Todos(context.Context) ([]*Todo, error)

Compilation exited abnormally with code 2 at Sun May 19 07:11:45

@hh
Copy link
Contributor

hh commented May 19, 2019

I added my environment:

https://github.com/ii/org/blob/master/research/gqlgen.org#my-environment

environ

go version
go version go1.12.3 linux/amd64

go env

go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/hippie/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/hippie/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/hippie/gqlgen-todos/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build045453696=/tmp/go-build -gno-record-gcc-switches"

@hh
Copy link
Contributor

hh commented May 19, 2019

I updated the documentation to fix #714 in #718.

@stale
Copy link

stale bot commented Aug 28, 2019

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.

@stale stale bot added the stale label Aug 28, 2019
@stale stale bot closed this as completed Sep 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants