{"id":13413709,"url":"https://github.com/99designs/gqlgen","last_synced_at":"2025-05-12T18:31:52.174Z","repository":{"id":37396507,"uuid":"121086193","full_name":"99designs/gqlgen","owner":"99designs","description":"go generate based graphql server library","archived":false,"fork":false,"pushed_at":"2025-05-05T11:28:47.000Z","size":15255,"stargazers_count":10304,"open_issues_count":362,"forks_count":1207,"subscribers_count":127,"default_branch":"master","last_synced_at":"2025-05-05T15:56:26.503Z","etag":null,"topics":["codegen","dataloader","gogenerate","golang","graphql","schema-first","subscriptions"],"latest_commit_sha":null,"homepage":"https://gqlgen.com","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/99designs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2018-02-11T04:54:11.000Z","updated_at":"2025-05-05T11:28:49.000Z","dependencies_parsed_at":"2023-09-28T21:01:22.096Z","dependency_job_id":"e1d83636-7610-41c8-b3dd-b488b3ecc547","html_url":"https://github.com/99designs/gqlgen","commit_stats":{"total_commits":2474,"total_committers":414,"mean_commits":5.975845410628019,"dds":0.8476151980598221,"last_synced_commit":"cdcab8a763a326ab1f5d8cbf8c7a4ce17644be86"},"previous_names":["vektah/gqlgen"],"tags_count":115,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgqlgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgqlgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgqlgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/99designs%2Fgqlgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/99designs","download_url":"https://codeload.github.com/99designs/gqlgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253797871,"owners_count":21965975,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codegen","dataloader","gogenerate","golang","graphql","schema-first","subscriptions"],"created_at":"2024-07-30T20:01:47.046Z","updated_at":"2025-05-12T18:31:52.151Z","avatar_url":"https://github.com/99designs.png","language":"Go","funding_links":[],"categories":["Popular","开源类库","Go","Libraries","Command line","Open source library","HarmonyOS","语言资源库","Query Language","graphql","查询语言","Implementations","golang","Relational Databases","\u003ca name=\"Go\"\u003e\u003c/a\u003eGo","API and RPC"],"sub_categories":["查询语言","Go Libraries","Generator","Query Language","Windows Manager","go","HTTP Clients","HTTP客户端","Go","Advanced and Specialized Tools"],"readme":"![gqlgen](https://user-images.githubusercontent.com/980499/133180111-d064b38c-6eb9-444b-a60f-7005a6e68222.png)\n\n# gqlgen [![Integration](https://github.com/99designs/gqlgen/actions/workflows/integration.yml/badge.svg)](https://github.com/99designs/gqlgen/actions) [![Coverage Status](https://coveralls.io/repos/github/99designs/gqlgen/badge.svg?branch=master)](https://coveralls.io/github/99designs/gqlgen?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/99designs/gqlgen)](https://goreportcard.com/report/github.com/99designs/gqlgen) [![Go Reference](https://pkg.go.dev/badge/github.com/99designs/gqlgen.svg)](https://pkg.go.dev/github.com/99designs/gqlgen) [![Read the Docs](https://badgen.net/badge/docs/available/green)](http://gqlgen.com/)\n\n## What is gqlgen?\n\n[gqlgen](https://github.com/99designs/gqlgen) is a Go library for building GraphQL servers without any fuss.\u003cbr/\u003e\n\n- **gqlgen is based on a Schema first approach** — You get to Define your API using the GraphQL [Schema Definition Language](http://graphql.org/learn/schema/).\n- **gqlgen prioritizes Type safety** — You should never see `map[string]interface{}` here.\n- **gqlgen enables Codegen** — We generate the boring bits, so you can focus on building your app quickly.\n\nStill not convinced enough to use **gqlgen**? Compare **gqlgen** with other Go graphql [implementations](https://gqlgen.com/feature-comparison/)\n\n## Quick start\n\n1. [Initialise a new go module](https://golang.org/doc/tutorial/create-module)\n\n```shell\nmkdir example\ncd example\ngo mod init example\n```\n\n2. Add `github.com/99designs/gqlgen` to your [project's tools.go](https://go.dev/wiki/Modules#how-can-i-track-tool-dependencies-for-a-module)\n\n```shell\nprintf '//go:build tools\\npackage tools\\nimport (_ \"github.com/99designs/gqlgen\"\\n _ \"github.com/99designs/gqlgen/graphql/introspection\")' | gofmt \u003e tools.go\ngo mod tidy\n```\n\n3. Initialise gqlgen config and generate models\n\n```shell\ngo run github.com/99designs/gqlgen init\ngo mod tidy\n```\n\n4. Start the graphql server\n\n```shell\ngo run server.go\n```\n\nMore help to get started:\n\n- [Getting started tutorial](https://gqlgen.com/getting-started/) - a comprehensive guide to help you get started\n- [Real-world examples](https://github.com/99designs/gqlgen/tree/master/_examples) show how to create GraphQL applications\n- [Reference docs](https://pkg.go.dev/github.com/99designs/gqlgen) for the APIs\n\n## Reporting Issues\n\nIf you think you've found a bug, or something isn't behaving the way you think it should, please raise an [issue](https://github.com/99designs/gqlgen/issues) on GitHub.\n\n## Contributing\n\nWe welcome contributions, Read our [Contribution Guidelines](https://github.com/99designs/gqlgen/blob/master/CONTRIBUTING.md) to learn more about contributing to **gqlgen**\n\n## Frequently asked questions\n\n### How do I prevent fetching child objects that might not be used?\n\nWhen you have nested or recursive schema like this:\n\n```graphql\ntype User {\n\tid: ID!\n\tname: String!\n\tfriends: [User!]!\n}\n```\n\nYou need to tell gqlgen that it should only fetch friends if the user requested it. There are two ways to do this:\n\n### Using Custom Models\n\nWrite a custom model that omits the friends field:\n\n```go\ntype User struct {\n  ID int\n  Name string\n}\n```\n\nAnd reference the model in `gqlgen.yml`:\n\n```yaml\n# gqlgen.yml\nmodels:\n  User:\n    model: github.com/you/pkg/model.User # go import path to the User struct above\n```\n\n### Using Explicit Resolvers\n\nIf you want to keep using the generated model, mark the field as requiring a resolver explicitly in `gqlgen.yml` like this:\n\n```yaml\n# gqlgen.yml\nmodels:\n  User:\n    fields:\n      friends:\n        resolver: true # force a resolver to be generated\n```\n\nAfter doing either of the above and running generate we will need to provide a resolver for friends:\n\n```go\nfunc (r *userResolver) Friends(ctx context.Context, obj *User) ([]*User, error) {\n  // select * from user where friendid = obj.ID\n  return friends,  nil\n}\n```\n\nYou can also use inline config with directives to achieve the same result\n\n```graphql\ndirective @goModel(\n\tmodel: String\n\tmodels: [String!]\n) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION\n\ndirective @goField(\n\tforceResolver: Boolean\n\tname: String\n\tomittable: Boolean\n\ttype: String\n) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION\n\ntype User @goModel(model: \"github.com/you/pkg/model.User\") {\n\tid: ID! @goField(name: \"todoId\")\n\tfriends: [User!]! @goField(forceResolver: true)\n}\n```\n\nThe field resolvers will be executed concurrently in separate goroutines. The degree of concurrency can be customized with the [`worker_limit` configuration attribute](https://gqlgen.com/config/).\n\n### Can I change the type of the ID from type String to Type Int?\n\nYes! You can by remapping it in config as seen below:\n\n```yaml\nmodels:\n  ID: # The GraphQL type ID is backed by\n    model:\n      - github.com/99designs/gqlgen/graphql.IntID # a go integer\n      - github.com/99designs/gqlgen/graphql.ID # or a go string\n      - github.com/99designs/gqlgen/graphql.UintID # or a go uint\n```\n\nThis means gqlgen will be able to automatically bind to strings or ints for models you have written yourself, but the\nfirst model in this list is used as the default type and it will always be used when:\n\n- Generating models based on schema\n- As arguments in resolvers\n\nThere isn't any way around this, gqlgen has no way to know what you want in a given context.\n\n### Why do my interfaces have getters? Can I disable these?\n\nThese were added in v0.17.14 to allow accessing common interface fields without casting to a concrete type.\nHowever, certain fields, like Relay-style Connections, cannot be implemented with simple getters.\n\nIf you'd prefer to not have getters generated in your interfaces, you can add the following in your `gqlgen.yml`:\n\n```yaml\n# gqlgen.yml\nomit_getters: true\n```\n\n## Other Resources\n\n- [Christopher Biscardi @ Gophercon UK 2018](https://youtu.be/FdURVezcdcw)\n- [Introducing gqlgen: a GraphQL Server Generator for Go](https://99designs.com.au/blog/engineering/gqlgen-a-graphql-server-generator-for-go/)\n- [Dive into GraphQL by Iván Corrales Solera](https://medium.com/@ivan.corrales.solera/dive-into-graphql-9bfedf22e1a)\n- [Sample Project built on gqlgen with Postgres by Oleg Shalygin](https://github.com/oshalygin/gqlgen-pg-todo-example)\n- [Hackernews GraphQL Server with gqlgen by Shayegan Hooshyari](https://www.howtographql.com/graphql-go/0-introduction/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F99designs%2Fgqlgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F99designs%2Fgqlgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F99designs%2Fgqlgen/lists"}