Yamashou / gqlgenc

This is Go library for building GraphQL client with gqlgen
MIT License
366 stars 64 forks source link

Missing ClientInterfaceName in GenerateConfig? #119

Open hyrefeldt-ourstudio opened 2 years ago

hyrefeldt-ourstudio commented 2 years ago

I get this error which looks like an error caused by some missing config

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x14807b3]

goroutine 1 [running]:
github.com/Yamashou/gqlgenc/clientgen.RenderTemplate(0xc0000a9ba0, 0xc006672320, 0x0, {0x1954870, 0x0, 0x0}, {0xc018f11740, 0x8, 0x8}, {0xc018f11600, ...}, ...)
        /Users/johanhyrefeldt/.gvm/pkgsets/go1.18/global/pkg/mod/github.com/!yamashou/gqlgenc@v0.0.6/clientgen/template.go:22 +0x313
github.com/Yamashou/gqlgenc/clientgen.(*Plugin).MutateConfig(0xc000091810, 0xc0000a9ba0)
        /Users/johanhyrefeldt/.gvm/pkgsets/go1.18/global/pkg/mod/github.com/!yamashou/gqlgenc@v0.0.6/clientgen/client.go:80 +0x607
github.com/Yamashou/gqlgenc/generator.Generate({0x163e5a8, 0xc0000300b0}, 0xc0001d61e0, {0xc0000e7ed8, 0x1, 0xc00005e601?})
        /Users/johanhyrefeldt/.gvm/pkgsets/go1.18/global/pkg/mod/github.com/!yamashou/gqlgenc@v0.0.6/generator/generater.go:52 +0x2e5
main.main()
        /Users/johanhyrefeldt/.gvm/pkgsets/go1.18/global/pkg/mod/github.com/!yamashou/gqlgenc@v0.0.6/main.go:30 +0x3b5

I'm using go1.18 so I have installed the executable gqlgenc via go install github.com/Yamashou/gqlgenc since go get doesn't install executables in go1.18. Prior to that I did run go get -u github.com/Yamashou/gqlgenc. The .gqlgenc.yml that i use looks like

model:
  package: backend
  filename: ./internal/backend/graphql-service_gen.go # https://github.com/99designs/gqlgen/tree/master/plugin/modelgen
client:
  package: backend
  filename: ./internal/backend/graphql-service.go # Where should any generated client go?
query:
  - "./internal/backend/graphql/graphql-service/query/*.graphql" # Where are all the query files located?
endpoint:
  url: <the url to the graphql api endpoint that I want to generate from>

What happens that the models in graphql-service_gen.go does seem to be generated correctly. And I have not done any changes to the queries in ./internal/backend/graphql/graphql-service/query so I don't expect any changes in ./internal/backend/graphql-service.go. But since I get the error above I want to double check that I'm not missing some important config.

basilgello commented 2 years ago

I have the same issue but you were on the right track spoting its root cause!

Seems @Yamashou fixed it in clientgenv2 (Yamashou/gqlgenc@7c74e5d7739df1e579d80261f30e928cdb242a3c) but not in clientgen.

The following patch fixes it for clientgen:

diff --git a/clientgen/template.go b/clientgen/template.go
index 8a8017e..89ffa89 100644
--- a/clientgen/template.go
+++ b/clientgen/template.go
@@ -19,7 +19,7 @@ func RenderTemplate(cfg *config.Config, query *Query, mutation *Mutation, fragme
                        "Operation":           operations,
                        "OperationResponse":   operationResponses,
                        "GenerateClient":      generateCfg.ShouldGenerateClient(),
-                       "ClientInterfaceName": generateCfg.ClientInterfaceName,
+                       "ClientInterfaceName": generateCfg.GetClientInterfaceName(),
                },
                Packages:   cfg.Packages,
                PackageDoc: "// Code generated by github.com/Yamashou/gqlgenc, DO NOT EDIT.\n",
Yamashou commented 2 years ago

@hyrefeldt-ourstudio

Do you have to use v1 clients? If so, I will try to correct v1 as well as v2