GraphQL
- 主要让 consumer/client 方使用便捷
- 核心特性/卖点 - 推荐开启
- GlobalID - ID 包含类型消息,能实现 ID ->
__typename - Graph Cache - 以
__typename+ id 来缓存 - 类似一个内存的 KV 数据库,可以直接查询- 配合自定义 resolver 将查询指向缓存 能大量减少查询
- 需要暴露
__typename, 但是一般影响不大
- Batch
- Subscription - EventSource, WebSocket
- 代码生成
- GlobalID - ID 包含类型消息,能实现 ID ->
- 推荐特性
- partial query - 只返回需要的字段
- Document Cache - 以查询维度来缓存
- persisted query - 通过 hash 来缓存查询, 避免暴露整个查询内容
- schema aware - 直接告诉查询引擎 schema 内容能让查询引擎更加智能
- 例如 判断 nullable 可以先返回缓存数据再发起查询
- federation - 多个 schema 合并
- schema stitching - 多个 schema 合并
- 特点
- 面向终端
- 接口数据格式由客户端定义
- 强类型
- GraphQL 规范
- Wikipedia GraphQLWikipediaGraphQL
- 实现
- graphql/graphql-jsGitHubgraphql/graphql-js
- A reference implementation of GraphQL for JavaScript
- graphql-java/graphql-javaGitHubgraphql-java/graphql-java
- GraphQL Java implementation
- neelance/graphql-goGitHubneelance/graphql-go
- GraphQL server with a focus on ease of use
- 强类型, 基于反射
- 直接基于 schema 解析
- vektah/gqlgenGitHubvektah/gqlgen
- go generate based graphql server library
- HNHacker NewsHacker News #16352611Hacker News
- graphql-go/graphqlGitHubgraphql-go/graphqlgraphql-go/graphql 是什么? · Golang GraphQL 解析、执行库 · Code First - 先 Go 代码,然后生成 GraphQL · 通过 struct 构建内容生成 graphql schema · 通过 struct 构建 resolver 和类型字段处理笔记:graphql
- An implementation of GraphQL for Go / Golang
- 弱类型, Resolver 返回 interface{}
- 解析的 schema 不能转为代码中的对象
- graphql-python/grapheneGitHubgraphql-python/graphene
- GraphQL framework for Python
- graphene-python.org
- graphql-js/grapheneGitHubgraphql-js/graphene
- graphql/graphql-jsGitHubgraphql/graphql-js
- 工具
- postgraphql/postgraphqlGitHubpostgraphql/postgraphql
- A GraphQL API created by reflection over a PostgreSQL schema.
- 2fd/graphdocGitHub2fd/graphdoc
- apollographql/graphql-syntaxGitHubapollographql/graphql-syntax
- A catalog of different packages and syntaxes to generate a GraphQL-JS schema
- graphql/graphiqlGitHubgraphql/graphiqlgraphql/graphiql · Explorer · Demo · adopted by · Hasura · Gitlab GraphQL Explorer · GitHub GraphQL Explorer · https://github.com/graphql/graphiql/blob/main/examples/graphiql-cd...笔记:GraphiQL
- An in-browser IDE for exploring GraphQL
- google/rejoinerGitHubgoogle/rejoiner
- HNHacker NewsHacker News #16193250Hacker News
- postgraphql/postgraphqlGitHubpostgraphql/postgraphql
- 接口参考
- Facebook Graph API
- GitHubGraphQL API v4
- 接口地址 api.github.com/graphqlLinkapi.github.com/graphql主要让 consumer/client 方使用便捷 · 核心特性/卖点 - 推荐开启 · GlobalID - ID 包含类型消息,能实现 ID -> · Graph Cache - 以 + id 来缓存 - 类似一个内存的 KV 数据库,可以直接查询笔记:GraphQL
- github 文档
- shopify 文档
- graphcms.com/docs/api_simple
- 参考
- Improve GraphQL Performance with Automatic Persisted Queries
- 优化查询大小
- 使用一个 Hash 值作为查询标识
- The future of state management
- 使用 GraphQL 来管理应用状态
- GraphQL.g4GitHub Fileantlr/grammars-v4/graphql/GraphQL.g4
- 语法参考
- Designing GraphQL Mutations
- 设计修改操作
- GraphQL schema stitching
- 合并多个 Schema
- A guide to authentication in GraphQL
- 认证
- 识别用户身份
- Authorization in GraphQL
- 鉴权
- 判断用户是否进行相关操作
- Reusable GraphQL schema directives
- Principled GraphQL
- Improve GraphQL Performance with Automatic Persisted Queries
- Relay
- facebook/relay
- Learn Relay
- What is a Query?
- The node and viewer fields
- Pagination
- 直接返回数组
- 返回数组接收翻页参数
- 返回链接
collections(first: Int!, after: String, reverse: Boolean): CollectionConnection!followers(first: Int, after: String, last: Int, before: String): FollowerConnection!
- 客户端
- Apollo React
- prisma-labs/graphql-requestGitHubprisma-labs/graphql-request
- 非常简单的客户端 - 配合 react-query 使用
- react-query vs apollo client
# 获取 Schema
npm install -g graphqurl
gq https://my-graphql-engine.com/v1/graphql --introspect > schema.graphql
gq https://my-graphql-engine.com/v1/graphql -H 'X-Hasura-Admin-Secret: adminsecretkey' --introspect > schema.graphql
gq https://my-graphql-engine.com/v1/graphql --introspect --format json > schema.json
# https://github.com/apollographql/apollo-tooling
# schema.json
npm install -g apollo
apollo schema:download --endpoint https://my-graphql-engine.com/v1/graphql
apollo schema:download --endpoint https://my-graphql-engine.com/v1/graphql --header 'X-Hasura-Admin-Secret: adminsecretkey'Apollo
- apollographqlGitHub Orgapollographql
FAQ
N + 1
DateTime
- graphql/graphql-js#550GitHub Issuegraphql/graphql-js#550
vs REST
TBD
skevy/graphiql-appGitHubskevy/graphiql-app Light, Electron-based Wrapper around GraphiQL
apollographql/apollo-serverGitHubapollographql/apollo-server
graphcool/graphql-playgroundGitHubgraphcool/graphql-playground GraphQL IDE for better development workflows (GraphQL Subscriptions, interactive docs & collaboration)
docker run -p 5000
postgraphql/postgraphql --connection postgres://POSTGRES_USER@POSTGRES_HOST/POSTGRES_SCHEMAchentsulin/awesome-graphqlGitHubchentsulin/awesome-graphql Awesome list of GraphQL & Relay
www.graphql.com graphql.org/learn/best-practices GraphQL Best Practices
www.apollographql.com Apollo provides a universal GraphQL API on top of your existing services, so you can build new application features fast without waiting on backend changes.
facebook/dataloaderGitHubfacebook/dataloader DataLoader is a generic utility to be used as part of your application's data fetching layer to provide a consistent API over various backends and reduce requests to those backends via batching and caching.
blog.datank.ai/graphql-grpc-part-1-54d92a109619 GraphQL & gRPC
relay
global id
- docs.github.com/cn/graphql/guides/using-global-node-ids
- github ID 格式 -
04:User583231 - New global ID format coming to GraphQL
- github ID 格式 -
- 支持用于接口处理 -
labelableId: ID! @possibleTypes(concreteTypes: ["Issue", "PullRequest"], abstractType: "Labelable") - Global Object Identification
- graphile/global-idsGitHubgraphile/global-ids
关联信息
反向链接和本文引用的外部资料。
References
GitHub
22 条- 2fd/graphdocgithub.com/2fd/graphdoc
- antlr/grammars-v4/graphql/GraphQL.g4github.com/antlr/grammars-v4/blob/master/graphql/GraphQL.g4
- apollographqlgithub.com/apollographql
- apollographql/apollo-servergithub.com/apollographql/apollo-server
- apollographql/graphql-syntaxgithub.com/apollographql/graphql-syntax
- chentsulin/awesome-graphqlgithub.com/chentsulin/awesome-graphql
- facebook/dataloadergithub.com/facebook/dataloader
- google/rejoinergithub.com/google/rejoiner
另有 14 个未显示 references。
Wikipedia
1 条- GraphQLWikipedia:GraphQL
Hacker News
2 条- Hacker News #16193250HN #16193250
- Hacker News #16352611HN #16352611
其他外链
37 条- 2fd.github.io/graphdoc/github2fd.github.io/graphdoc/github
- 2fd.github.io/graphdoc/shopify2fd.github.io/graphdoc/shopify
- api.github.com/graphqlapi.github.com/graphql
- blog.datank.ai/graphql-grpc-part-1-54d92a109619blog.datank.ai/graphql-grpc-part-1-54d92a109619
- blog.runscope.com/posts/you-might-not-need-graphqlblog.runscope.com/posts/you-might-not-need-graphql
- dev-blog.apollodata.com/131fb3a177d1dev-blog.apollodata.com/131fb3a177d1
- dev-blog.apollodata.com/a-guide-to-authentication-in-graphql-e002a4039d1dev-blog.apollodata.com/a-guide-to-authentication-in-graphql-e002a4039d1
- dev-blog.apollodata.com/auth-in-graphql-part-2-c6441bcc4302dev-blog.apollodata.com/auth-in-graphql-part-2-c6441bcc4302
另有 29 个未显示 references。
另有 43 个 references 未显示。