Migrating from graphql-go
github.com/gql-go/graphql continues
github.com/graphql-go/graphql from its
last release, v0.8.1. The package name and the API are the same: migrating is a
change of module path, and code written for v0.8.1 keeps compiling and behaving
the same way.
Before you start
- Go version. Releases from
v0.10.0require Go 1.27 or newer. With the defaultGOTOOLCHAIN=auto, thegocommand downloads it when needed. If you cannot upgrade Go yet, usev0.9.x, which builds with Go 1.21 and receives security fixes for the period stated in the security policy. - Move every import together.
github.com/graphql-go/graphqlandgithub.com/gql-go/graphqlare different modules, so their types are different types: a schema built with one cannot be passed to code that imports the other. Migrate all packages in your module at once, and usegithub.com/gql-go/handlerin place ofgithub.com/graphql-go/handler. A third-party package that importsgraphql-go/graphqlhas to move too before it can work with your schema.
Steps
Replace the import paths in your Go files. On Linux and macOS:
grep -rl --null --include='*.go' 'github.com/graphql-go/' . | xargs -0 perl -pi -e 's#github\.com/graphql-go/(graphql|handler)\b#github.com/gql-go/$1#g'Or use your editor’s search and replace:
github.com/graphql-go/graphql -> github.com/gql-go/graphql github.com/graphql-go/handler -> github.com/gql-go/handlerAdd the new modules and drop the old ones from
go.mod. With Go 1.27 or newer:go get github.com/gql-go/graphql@latest go get github.com/gql-go/handler@latest # if you use the handler go mod tidygo getraises thegodirective of your module to 1.27 if it is lower.To stay on Go 1.21, use the
v0.9line of the library and thev0.3line of the handler, which build with it:go get github.com/gql-go/graphql@v0.9 go get github.com/gql-go/handler@v0.3 # if you use the handler go mod tidyIf your module has a
vendordirectory, update it aftergo mod tidywithgo mod vendor, orGOWORK=off go mod vendorwhen the module is part of a workspace. A workspace that vendors at its root usesgo work vendor(Go 1.22 or newer).Build and run your tests:
go build ./... go test ./...
What stays the same
The API of v0.8.1 is kept as it is: no exported symbol is removed or changed,
and the inherited test suite runs unmodified in CI. This includes usage that is
not formally documented but that production code depends on, such as
DefaultResolveFn resolving struct fields by their json tag, ResolveParams
and ResolveInfo built by hand, Schema.AppendType after NewSchema, and
panics in resolvers turned into field errors.
New behaviour is opt-in: it is enabled through configuration, and the default stays as it was. Fixes change output only where it was broken before, such as a panic, a race or a wrong result.
Changes that may need action
Rarely, a fix or a security fix changes something that working code can observe. These are all of them:
gql-go/handlerv0.4.1andv0.3.2: mutations run only from aPOSTwith anapplication/jsonorapplication/graphqlbody.graphql-go/handlerran them fromGETrequests and form bodies too, which allowed cross-site request forgery with cookie authentication (GHSA-4gfj-j6mf-x2mh). Clients that send mutations that way must send them asPOSTwith JSON; see Serving over HTTP.v0.14.0: an input object field whose name is not a valid GraphQL name, such asfirst-name, makesNewSchemaandAppendTypereturn an error. Before, the field was dropped without an error, so no client could use it; rename the field (#209).v0.14.0: aSchema.AppendTypethat returns an error leaves the schema as it was. Code that ignored the error and used the rejected type no longer finds it; check the error (#204).v0.14.0:Schema.AppendTypecalled while anotherAppendTypeis in progress on the same schema, as from a fields thunk, returnsErrAppendTypeInProgress. It could succeed before for types without interfaces; append the type after the outer call returns (#210).
Following new releases
The guides describe the latest release, and mark each feature added after
v0.9.0 with the version that introduced it. The
release notes list every change,
grouped by type, with a link to the pull request that explains it, and
Announcements
covers each minor release.
Older versions
The tags v0.4.18 to v0.8.1 in this repository are inherited from
graphql-go/graphql and declare that module path. They are retracted: go get
warns about them and go list -m -versions hides them. To use those versions,
keep importing github.com/graphql-go/graphql.