Skip to content
go generate based graphql server library
Go JavaScript Other
Branch: master
Clone or download
vvakame Merge pull request #985 from Khan/no-key-needed
Correctly generate a federated schema when no entity has a `@key`.
Latest commit f7a6772 Jan 23, 2020
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci update lint in circleci Aug 7, 2019
.github Update stale.yml Aug 28, 2019
api bump x/tools for consistent import formatting Jan 15, 2020
bin Update release process to keep tags on master Jun 27, 2019
client Fix websocket connections on test client Sep 25, 2019
cmd remove all references to deprecated handler package Nov 11, 2019
codegen Remove empty lines on DirectiveRoot generation Jan 20, 2020
complexity Combine root handlers in ExecutableSchema into a single Exec method Nov 5, 2019
docs fix: explicitly exclude trailing comma from link Jan 7, 2020
example Remove empty lines on DirectiveRoot generation Jan 20, 2020
graphql Add context.Context to graphql.Cache interface's methods Jan 20, 2020
handler Add context.Context to graphql.Cache interface's methods Jan 20, 2020
integration review feedback Jan 15, 2020
internal Merge pull request #983 from vikstrous/name-for-package-global Jan 15, 2020
plugin Correctly generate a federated schema when no entity has a `@key`. Jan 23, 2020
testdata Add apollo tracing Oct 30, 2019
.dockerignore convert existing tests to jest Aug 9, 2018
.editorconfig Use docker in docker for the existing testsuite Aug 8, 2018
.gitattributes Add fully customizable resolver errors Apr 27, 2018
.gitignore update appveyour to not rely on main Jan 10, 2019
.golangci.yml remove all references to deprecated handler package Nov 11, 2019
CONTRIBUTING.md Consolidate Introduction documents Mar 4, 2019
LICENSE rename repo Feb 11, 2018
README.md Add Link to Sample Project with GQLGen and Postgres Jan 6, 2020
TESTING.md Add a PR template Aug 23, 2018
appveyor.yml force clean git checkout Nov 28, 2019
go.mod bump x/tools for consistent import formatting Jan 15, 2020
go.sum bump x/tools for consistent import formatting Jan 15, 2020
main.go Reintroduce main package in root Feb 18, 2019
tools.go bump x/tools for consistent import formatting Jan 15, 2020

README.md

gqlgen CircleCI Read the Docs

What is gqlgen?

gqlgen is a Go library for building GraphQL servers without any fuss. gqlgen is:

  • Schema first — Define your API using the GraphQL Schema Definition Language.
  • Type safe — You should never see map[string]interface{} here.
  • Codegen — Let us generate the boring bits, so you can build your app quickly.

Feature Comparison

Getting Started

First work your way through the Getting Started tutorial.

If you can't find what your looking for, look at our examples for example usage of gqlgen.

Reporting Issues

If you think you've found a bug, or something isn't behaving the way you think it should, please raise an issue on GitHub.

Contributing

Read our Contribution Guidelines for information on how you can help out gqlgen.

Frequently asked questions

How do I prevent fetching child objects that might not be used?

When you have nested or recursive schema like this:

type User {
  id: ID!
  name: String!
  friends: [User!]!
}

You need to tell gqlgen that we should only fetch friends if the user requested it. There are two ways to do this.

Custom Models

Write a custom model that omits the Friends model:

type User struct {
  ID int
  Name string
}

And reference the model in gqlgen.yml:

# gqlgen.yml
models:
  User:
    model: github.com/you/pkg/model.User # go import path to the User struct above

Explicit Resolvers

If you want to Keep using the generated model: mark the field as requiring a resolver explicitly in gqlgen.yml:

# gqlgen.yml
models:
  User:
    fields:
      friends:
        resolver: true # force a resolver to be generated

After doing either of the above and running generate we will need to provide a resolver for friends:

func (r *userResolver) Friends(ctx context.Context, obj *User) ([]*User, error) {
  // select * from user where friendid = obj.ID
  return friends,  nil
}

IDs are strings but I like ints, why cant I have ints?

You can by remapping it in config:

models:
  ID: # The GraphQL type ID is backed by
    model:
      - github.com/99designs/gqlgen/graphql.IntID # An go integer
      - github.com/99designs/gqlgen/graphql.ID # or a go string

This means gqlgen will be able to automatically bind to strings or ints for models you have written yourself, but the first model in this list is used as the default type and it will always be used when:

  • Generating models based on schema
  • As arguments in resolvers

There isnt any way around this, gqlgen has no way to know what you want in a given context.

Other Resources

You can’t perform that action at this time.