web-ridge / gqlgen-sqlboiler

This is a plugin for gqlgen to generate converts + filter queries and resolvers for sqlboiler
MIT License
74 stars 13 forks source link

resolver.go fails to generate. #51

Closed orible closed 3 years ago

orible commented 3 years ago

8:15PM DBG [resolver] generate file 8:15PM ERR could not parse golang file error="src.go:1:1: expected 'package', found 'EOF'" error while trying generate resolver and converts resolver-webridge: errors while writing template to E:/server/resolver.go writeError: , contentError: formatting: 38:14: unknown escape sequence, importError: E:/server/resolver.go:38:14: unknown escape sequence exit status 3

And this is the contents of Resolver.go:

" package

"

orible commented 3 years ago

Not sure which input is being referenced by "contentError"

RichardLindhout commented 3 years ago

Is this v3.1.2 or v3.1.1?

RichardLindhout commented 3 years ago

Maybe it works if your project is inside your GOPATH but it should also work outside but maybe try to put in the GOPATH

Source (https://github.com/golang/go/issues/7266)

orible commented 3 years ago

Interesting, 🤔

My project is in my gopath, I append the "E:/src/" folder (or something similar to that effect) to the env path.

I initially had trouble with the boiler parse and schema write step, but after adding a branch for null.JSON => string, it's succeeding there.

Can't quite tell what's going on when it's complaining about src.go.

orible commented 3 years ago

🤔 As you say, it might very well be my gopath setup, I'll have a go at poking around with that.

orible commented 3 years ago

Traced the bug to:

v3@v3.1.2/templates/templates.go

54: node, err := parser.ParseFile(fSet, "src.go", string(importFixedContent), 0)

orible commented 3 years ago

https://github.com/golang/go/blob/0e85fd7561de869add933801c531bf25dee9561c/src/go/ast/example_test.go

I notice this occurs as so:

"// This example demonstrates how to inspect the AST of a Go program"

orible commented 3 years ago

the resolver plugin is trying to parse an empty syntax tree source

orible commented 3 years ago

https://github.com/web-ridge/gqlgen-sqlboiler/blob/f17b21c9ceec5fdda5cfe7309865c6c5ed5e2dda/templates/templates.go#L51

importsError not handled

importFixedContent is empty

https://github.com/web-ridge/gqlgen-sqlboiler/blob/f17b21c9ceec5fdda5cfe7309865c6c5ed5e2dda/templates/templates.go#L54

orible commented 3 years ago

importsError returning:

:<go/scanner.Error> Pos:<go/token.Position> Filename:"E:/server/resolver.go" Offset:853 Line:38 Column:14 Msg:"unknown escape sequence"

orible commented 3 years ago

pre parse resolver.go

at the end of the import header:

`
github.com/rs/zerolog/log"

           . "server/helpers"
    dm "server/model/database"

    fm "server/graphql_models"

    gm "server\graphql_models"

` It seems it's added an import with an incorrect directory separator

orible commented 3 years ago

https://github.com/web-ridge/gqlgen-sqlboiler/blob/f17b21c9ceec5fdda5cfe7309865c6c5ed5e2dda/resolver_plugin.go#L97

Providing incorrect directory join

https://github.com/web-ridge/gqlgen-sqlboiler/blob/f17b21c9ceec5fdda5cfe7309865c6c5ed5e2dda/resolver_plugin.go#L154

given directory path with single backslashes

Eg:

E:\src\myapp\resolver.go

orible commented 3 years ago

https://github.com/99designs/gqlgen/blob/997da421b0b80884fcb43c8c6a22d747564b301c/codegen/config/package.go#L17

This function instead of

https://github.com/99designs/gqlgen/blob/997da421b0b80884fcb43c8c6a22d747564b301c/codegen/config/package.go#L24

correctly handles transforming the system path to a valid one

See:

https://github.com/99designs/gqlgen/blob/997da421b0b80884fcb43c8c6a22d747564b301c/internal/code/imports.go#L81

orible commented 3 years ago

Problem semi fixed.

Though I'll have to create new issue requests for some more problems I've encountered.

orible commented 3 years ago

See pull: https://github.com/web-ridge/gqlgen-sqlboiler/pull/53

RichardLindhout commented 3 years ago

Thanks a lot!! I did a pre-release with your PR