Comments (10)
I think the way to do this may be to conditional-compile it for 1.16+, and use the current system for older versions. That is, we support a standalone binary on 1.16+, and 1.13+ as long as we can find the templates (e.g. go run
or a build from a local checkout).
from genqlient.
Update: apparently that doesn't work because go:embed
also requires the go.mod version (which is kinda-sorta the module's min-version) to be 1.16+, not just the build tag.
@StevenACoffman do you know if there's a way around this? I think we're sadly at least 6 months, maybe more, from it being reasonable to require 1.16+.
from genqlient.
I forgot I never circled back on this because I wasn't sure what your question was. Please forgive me if you know all this and none of it is what you wanted to work around.
As you have already figured out, if a module declares go 1.15
in its go.mod
, and then only imports the "embed" package in a Go file guarded by:
//go:build go1.16
// +build go1.16
Note: This guard actually didn't work for a few versions of Go, so for instance in Go 1.15, you need Go 1.15.12 or it would complain anyway. I forget what version of Go 1.14 ignoring build tag guarded embed directives was backported to.
However, you probably want to build this file with Go 1.17 as well. Multiple build tags on the same line in a .go file causes go build to interpret them using OR logic. If we put them on separate lines, then go build will interpret those tags using AND logic, instead, so I think you want to change it to:
//go:build go1.17
// +build go1.16 go1.17
And then I think the build tags for the prior to Go 1.16 versions should be:
//go:build !go1.17
// +build !go1.16
// +build !go1.17
Since //go:build
is the new conditional compilation directive introduced in Go 1.17, so that's the only version that is relevant for those lines above.
Also, for the Go 1.15 file, you would need to have an alternative implementation like go-bindata or pkger or do the box thing.
from genqlient.
Unless I messed something up, the issue was none of those! You can see what I did here: e3e3e8e, and I believe it includes everything you said (except that we don't need a go1.17 tag because the go1.16 tag actually means 1.16+). The problem is that go:embed
apparently also depends on the language version in the go.mod
, so you can't even use it behind a go:build
tag, at least as far as I can see. But I may still have been doing something wrong!
from genqlient.
You can use go:embed
behind a go:build
tag only on Go 1.15.11+ assuming your go.mod also targets Go 1.15.
Assuming you have ASDF installed to manage Go versions (and you have ASDF_GOLANG_VERSION=1.15.13 and ASDF_GOLANG_VERSION=1.16.6) installed, you can demonstrate for yourself this works:
git clone [email protected]:a609fe65f6b76457a620af08b5cbb8d7.git gomod-build-issue
cd gomod-build-issue
./script.sh
I ran it fine on different various different Go versions, but it does break on Go 1.15.10 and lower.
See golang/go#43980 (comment) where in Go 1.15.11:
I believe that the build tag solution now works correctly with 1.15.11 - go mod tidy is now resilient to stdlib imports which don't exist.
from genqlient.
Ah interesting. Let's just wait until we're ready to drop 1.15, I think that will be simpler than trying to make sure everyone has the right version and this doesn't seem to have caused much trouble in practice.
from genqlient.
I'm trying to use genqlient
with Bazel and am running into issues because of the way templates are looked up. They have a hardcoded file path that isn't accurate when used within a Bazel build environment. Can we revisit this? At this point Go is on version 1.18. Is it reasonable to bump the min version to 1.16?
It looks like you've already fixed this on main
. Can you cut a new version?
from genqlient.
Just released v0.5.0, which includes this. Thanks for the poke!
from genqlient.
Thanks! I'm not seeing it though:
➜ external go list -m -versions github.com/Khan/genqlient
github.com/Khan/genqlient v0.1.0 v0.2.0 v0.3.0 v0.4.0
I did patch the current main
commit into my project though and it's working beautifully! The go:embed
API is really nice 😄.
from genqlient.
Whoops, forgot to actually push the tag. Try again now!
from genqlient.
Related Issues (20)
- Errors with Strawberry Generated Schema including `JSON` Scalar HOT 1
- Tests failing on Go 1.22+
- Lint failing on 1.21+
- Using `# @genqlient(typename: "Webhook")` adds `json:"-"` to generated struct (?) HOT 7
- Support `optional: generic` inline
- Support, new release HOT 1
- How can I get response header HOT 1
- Allow globs for schema/queries to be optional, if at least one file is found HOT 1
- Inconsistent JSON Tag Generation for Required Boolean Fields in Structs HOT 3
- Optional input with required output HOT 1
- Support for @authenticated directive HOT 2
- Standardise the error return from http request HOT 3
- Add option to not generate the client, only the types HOT 2
- Option to generate multiple files HOT 2
- Using an Interface inline fragment inside of a Union is awkward to unpack HOT 3
- Optional parameter made required HOT 2
- schema.md has some formatting issues
- Running genqlient on large schemas fails HOT 4
- use_struct_references not compatible with new omitempty validation logic HOT 9
- The Generated GraphQl query with mutation throws error for LINEAR GraphQL Query endpoint HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from genqlient.