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

error while running go generate #2211

Closed
shimish2 opened this issue May 26, 2022 · 10 comments
Closed

error while running go generate #2211

shimish2 opened this issue May 26, 2022 · 10 comments

Comments

@shimish2
Copy link

What happened?

I am getting error while running go generate

ec._fieldMiddleware undefined (type *executionContext has no field or method _fieldMiddleware)

What did you expect?

go generate should run successfully. After downgrading gqlgen to v1.14.0 & gqlparser to v2.2.0, go generate was successful.

versions

  • go run github.com/99designs/gqlgen version?
    v0.17.8
  • go version?
    1.18
shimish2 added a commit to shimish2/zot that referenced this issue May 26, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
@frederikhors
Copy link
Collaborator

Please create a reproduction repo.

shimish2 added a commit to shimish2/zot that referenced this issue May 26, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
@shimish2
Copy link
Author

shimish2 commented May 26, 2022

Please checkout this changes https://github.com/project-zot/zot/tree/main/pkg/extensions/search and try to run go generate from search directory.

shimish2 added a commit to shimish2/zot that referenced this issue May 26, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
@frederikhors
Copy link
Collaborator

Can you try with 0.17.9, please?

@shimish2
Copy link
Author

tried with 0.17.9 and got same error.

@ashishb
Copy link

ashishb commented Jun 1, 2022

Same issue with the latest version and downgrading gqlgen to v0.14.0 works for me as well.

shimish2 added a commit to shimish2/zot that referenced this issue Jun 1, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
@andaaron
Copy link

andaaron commented Jul 15, 2022

Hi,
Looks like sticking to the v0.14.0 workaround is not working with Go 1.18 because it doesn't have the fix for #1961 (works with 1.17).
Do we have a long term solution?

andaaron pushed a commit to andaaron/zot that referenced this issue Jul 15, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
andaaron pushed a commit to andaaron/zot that referenced this issue Jul 15, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
andaaron pushed a commit to andaaron/zot that referenced this issue Jul 15, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
andaaron pushed a commit to andaaron/zot that referenced this issue Jul 16, 2022
gqlgen v0.17.8 has some issue while generating code.

use gqlgen v0.14.0 and gqlparser v2.2.0 until fixed.

Raised an issue on gqlgen repo 99designs/gqlgen#2211

Signed-off-by: Shivam Mishra <shimish2@cisco.com>
@manisharma
Copy link

any updates here ? go run github.com/99designs/gqlgen generate still fails

$ go version
go version go1.18 darwin/arm64

@andaaron
Copy link

For our project we started from scratch with gqlgen init, replaced the schema with ours, and did some code refactoring to move our resolvers to match the new file/folder structure (before this we did not have a gqlgen.yml, or a schema.resolvers.go file - the methods in schema.resolvers.go were implemented in resolvers.go).

Currently it's working with latest gqlgen and go1.18.

@frederikhors
Copy link
Collaborator

This is not a problem anymore with gqlgen latest versions and Go 1.16.x, 1.17.x, 1.18x.

Maybe you can use gqlgen init from scratch in a new dir and notice the differences from your project.

Or you can re-check re-reading the config page.

Definitely this is not something wrong with latest versions, hence I'm closing this.

@andrey-bobryshev-90poe
Copy link

I found the cause of this issue. If you running generate with no gqlgen.yml file you will be getting this error because generated code will contain this piece of code:

	resTmp := ec._fieldMiddleware(ctx, obj, func(rctx context.Context) (interface{}, error) {
		ctx = rctx // use context from middleware stack in children
		return obj.ID, nil
	})

This is where it comes from

{{- if $.AllDirectives.LocationDirectives "FIELD" }}
resTmp := ec._fieldMiddleware(ctx, {{if $object.Root}}nil{{else}}obj{{end}}, func(rctx context.Context) (interface{}, error) {
{{ template "field" $field }}
})
{{ else }}

Once you add gqlgen.yml everything works well.
Probably $.AllDirectives.LocationDirectives var initialises wrong without config file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants