99designs/gqlgen — 10.7k★ trên GitHub (Go). go generate based graphql server library
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
gqlgen is a Go library for building GraphQL servers without any fuss.
gqlgen is based on a Schema first approach — You get to Define your API using the GraphQL Schema Definition Language.
gqlgen prioritizes Type safety — You should never see map[string]interface{} here.
gqlgen enables Codegen — We generate the boring bits, so you can focus on building your app quickly.
Still not convinced enough to use gqlgen? Compare gqlgen with other Go graphql implementations
Quick start
Initialise a new go module
mkdir example
cd example
go mod init example
Add github.com/99designs/gqlgen to your project, as a tool dependency
go get -tool github.com/99designs/gqlgen
Initialise gqlgen config and generate models
go tool gqlgen init
Start the graphql server
go run server.go
More help to get started:
Getting started tutorial - a comprehensive guide to help you get started
Real-world examples show how to create GraphQL applications
Reference docs for the APIs
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
We welcome contributions, Read our Contribution Guidelines to learn more about contributing to 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 it should only fetch friends if the user requested it. There are two ways to do this:
Using Custom Models
Write a custom model that omits the friends field:
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
Using Explicit Resolvers
If you want to keep using the generated model, mark the field as requiring a resolver explicitly in gqlgen.yml like this:
# 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
}
You can also use inline config with directives to achieve the same result
directive @goModel(
model: String
models: [String!]
) on OBJECT | INPUT_OBJECT | SCALAR | ENUM | INTERFACE | UNION
directive @goField(
forceResolver: Boolean
name: String
omittable: Boolean
type: String
autoBindGetterHaser: Boolean
forceGenerate: Boolean
batch: Boolean
) on INPUT_FIELD_DEFINITION | FIELD_DEFINITION
type User @goModel(model: "github.com/you/pkg/model.User") {
id: ID! @goField(name: "todoId")
friends: [User!]! @goField(forceResolver: true)
# When omit_resolver_fields is enabled, this field will still be generated in the struct
data: String! @goField(forceResolver: true, forceGenerate: true)
}
The field resolvers will be executed concurrently in separate goroutines. The degree of concurrency can be customized with the worker_limit configuration attribute.
Can I change the type of the ID from type String to Type Int?
Yes! You can by remapping it in config as seen below:
models:
ID: # The GraphQL type ID is backed by
model:
- github.com/99designs/gqlgen/graphql.IntID # a go integer
- github.com/99designs/gqlgen/graphql.ID # or a go string
- github.com/99designs/gqlgen/graphql.UintID # or a go uint
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 isn't any way around this, gqlgen has no way to know what you want in a given context.
Why do my interfaces have getters? Can I disable these?
These were added in v0.17.14 to allow accessing common interface fields without casting to a concrete type.
However, certain fields, like Relay-style Connections, cannot be implemented with simple getters.
If you'd prefer to not have getters generated in your interfaces, you can add the following in your gqlgen.yml:
# gqlgen.yml
omit_getters: true
Other Resources
Christopher Biscardi @ Gophercon UK 2018
Introducing gqlgen: a GraphQL Server Generator for Go
Dive into GraphQL by Iván Corrales Solera
Sample Project built on gqlgen with Postgres by Oleg Shalygin
Hackernews GraphQL Server with gqlgen by Shayegan Hooshyari
99designs/gqlgen có 10.7k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/99designs/gqlgen. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
99designs/gqlgen có phải mã nguồn mở không?
Có — 99designs/gqlgen phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/99designs/gqlgen.
99designs/gqlgen có trang demo không?
Dự án có trang chủ ở https://gqlgen.com. Tab "Readme" ở trang này thường có ảnh chụp và hướng dẫn bắt đầu nhanh.
99designs/gqlgen là gì?
99designs/gqlgen (99designs/gqlgen) là dự án Go trên GitHub. Theo mô tả gốc: go generate based graphql server library
99designs/gqlgen so với các dự án Backend khác thế nào?
99designs/gqlgen được TopGit xếp vào nhóm Backend, với 10.7k sao GitHub và viết bằng Go. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Cùng nhóm Backend còn repo nào?
99designs/gqlgen thuộc nhóm Backend trên TopGit, cùng 7 topic GitHub. Trang Trending và Topics liệt kê các repo cùng số sao và cùng ngôn ngữ để so sánh.
Đọc thêm về 99designs/gqlgen ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/99designs/gqlgen là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về gqlgen?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về gqlgen.