GraphQL LogoGraphQL

程式碼

使用 GraphQL

由於 GraphQL 是一種通訊模式,因此有許多工具可以協助您開始使用支援各種語言的 GraphQL。

語言支援

排序方式

JavaScript

伺服器

GraphQL.js

最後發布6 個月前
星號20k
授權MIT 授權

GraphQL 規格的參考實作,設計用於在 Node.js 環境中執行 GraphQL。

若要從命令列執行 GraphQL.js hello world 腳本

npm install graphql

然後在 hello.js 中執行 node hello.js

var { graphql, buildSchema } = require("graphql")
var schema = buildSchema(`
type Query {
hello: String
}
`)
var rootValue = { hello: () => "Hello world!" }
var source = "{ hello }"
graphql({ schema, source, rootValue }).then(response => {
console.log(response)
})

graphql-yoga

最後發布1 週前
星號8k
授權MIT 授權

GraphQL Yoga 是一款包含電池的跨平台 GraphQL over HTTP 規格相容 GraphQL 伺服器,使用 Envelop 和 GraphQL Tools。

  • 建構於 Fetch API RequestResponse 物件周圍
  • 相容 GraphQL over HTTP
  • 由 Envelop 提供動力的可擴充 GraphQL 引擎
  • GraphQL 訂閱透過 HTTP
  • 使用 GraphQL 處理檔案上傳
  • 與 AWS Lambda、Cloudflare Workers、Deno、Express、Next.js、SvelteKit 等整合。

使用 graphql-yoga 執行 hello world 伺服器

npm install graphql-yoga graphql

然後使用 createServer 匯入建立伺服器

import { createServer } from "http"
import { createSchema, createYoga } from "graphql-yoga"
createServer(
createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => "Hello Hello Hello",
},
},
}),
})
).listen(4000, () => {
console.info("GraphQL Yoga is listening on http://localhost:4000/graphql")
})

根據您的部署目標,您可能需要使用其他函式庫。請參閱 文件 以取得進一步的詳細資訊。

Mercurius

最後釋出1 天前
星數2k
授權MIT 授權

Mercurius 是 Fastify 的彈性且可擴充 GraphQL 介面卡,Fastify 是一個超快速的網路架構,具有最少的開銷和強大的外掛程式架構。

使用 mercurius 執行 hello world 腳本

npm install fastify mercurius

然後在 app.js 中執行 node app.js

const Fastify = require("fastify")
const mercurius = require("mercurius")
const schema = `
type Query {
hello(name: String): String!
}
`
const resolvers = {
Query: {
hello: async (_, { name }) => `hello ${name || "world"}`,
},
}
const app = Fastify()
app.register(mercurius, {
schema,
resolvers,
})
app.listen(3000)
// Call IT!
// curl 'http://localhost:3000/graphql' \
// -H 'content-type: application/json' \
// --data-raw '{"query":"{ hello(name:\"Marcurius\") }" }'

GraphQL-WS

最後釋出1 個月前
星數2k
授權MIT 授權

一致、零依賴、延遲、簡單,符合 GraphQL over WebSocket 協定的伺服器和用戶端。

Apollo Server

最後釋出2 週前
星數14k
授權MIT 授權

來自 Apollo 的 GraphQL 伺服器,可與任何 Node.js HTTP 架構搭配使用

使用 Apollo Server 執行 hello world 伺服器

npm install @apollo/server graphql

然後在 server.js 中執行此程式碼的 node server.js

import { ApolloServer } from "@apollo/server"
import { startStandaloneServer } from "@apollo/server/standalone"
const server = new ApolloServer({
typeDefs,
resolvers,
})
const { url } = await startStandaloneServer(server)
console.log(`🚀 Server ready at ${url}`)

Apollo Server 有一個內建的獨立 HTTP 伺服器和 Express 中介軟體,並有一個架構整合 API,支援所有 Node.js HTTP 伺服器架構和無伺服器環境,透過社群整合。

Apollo Server 有 外掛程式 API、與 Apollo Studio 整合,以及效能和安全性功能,例如 快取自動持續查詢CSRF 防護

GraphQL-SSE

最後發布3 個月前
星星數362
授權MIT 授權

零相依性、HTTP/1 安全、簡單,透過伺服器傳送事件協定的 GraphQL 伺服器和用戶端。

GraphQL-HTTP

最後發布6 個月前
星星數272
授權MIT 授權

簡單、可插入、零相依性,符合 GraphQL over HTTP 規範的伺服器、用戶端和稽核套件。

GraphQLBox 伺服器

星星數23
授權MIT 授權

一個可擴充的 GraphQL 伺服器,具有快取、要求剖析、除錯、訂閱等模組...

以下範例安裝並初始化 GraphQLBox 伺服器,並啟用持續快取和除錯。

npm install @graphql-box/core @graphql-box/server @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/execute @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/redis @cachemap/constants @cachemap/types
import Cachemap from "@cachemap/core"
import redis from "@cachemap/redis"
import reaper from "@cachemap/reaper"
import CacheManager from "@graphql-box/cache-manager"
import Client from "@graphql-box/client"
import DebugManager from "@graphql-box/debug-manager"
import Execute from "@graphql-box/execute"
import RequestParser from "@graphql-box/request-parser"
import Server from "@graphql-box/server"
import { makeExecutableSchema } from "@graphql-tools/schema"
import { performance } from "perf_hooks"
import { schemaResolvers, schemaTypeDefs } from "./schema"
import logger from "./logger"
const schema = makeExecutableSchema({
typeDefs: schemaTypeDefs,
resolvers: schemaResolvers,
})
const server = new Server({
client: new Client({
cacheManager: new CacheManager({
cache: new Cachemap({
name: "server-cache",
reaper: reaper({ interval: 300000 }),
store: redis(/* configure */),
}),
cascadeCacheControl: true,
typeCacheDirectives: {
// Add any type specific cache control directives in the format:
// TypeName: "public, max-age=3",
},
}),
debugManager: new DebugManager({
environment: "server",
log: (...args) => {
logger.log(...args)
},
name: "SERVER",
performance,
}),
requestManager: new Execute({ schema }),
requestParser: new RequestParser({ schema }),
}),
})
// Meanwhile... somewhere else in your code
app.use("api/graphql", graphqlServer.request())

客戶端

Apollo Client

最後釋出1 天前
星星19k
授權MIT 授權

一個強大的 JavaScript GraphQL 客戶端,設計用於與 React、React Native、Angular 2 或純 JavaScript 搭配使用。

urql

最後發布1 週前
星號8k
授權MIT 授權

一個高度可自訂且多功能的 GraphQL 客戶端,隨著您的成長,您可以添加正規化快取等功能。

urql 是 GraphQL 客戶端,提供一組針對多個架構的輔助程式。它被建置為高度可自訂且多功能,因此您可以從開始您的第一個 GraphQL 專案,一路到建置複雜的應用程式和實驗 GraphQL 客戶端。

  • 目前支援 React、React Native、Preact、Svelte 和 Vue,並由 GraphQL Code Generator 支援。
  • 邏輯卻簡單的預設行為和文件快取,以及透過 @urql/exchange-graphcache 進行正規化快取
  • 透過「交換」(附加元件套件)完全自訂行為

Relay

最後釋出1 個月前
星星18k
授權MIT 授權

Facebook 用於建立與 GraphQL 後端通訊的 React 應用程式的架構。

Relay 是用於建立資料驅動 React 應用程式的 JavaScript 架構。

  • 宣告式:不再使用命令式 API 與資料儲存庫通訊。只要使用 GraphQL 宣告你的資料需求,然後讓 Relay 找出如何以及何時擷取你的資料。
  • 並置:查詢與依賴它們的檢視並列,因此你可以輕鬆地推論你的應用程式。Relay 將查詢彙總成有效率的網路要求,只擷取你需要的内容。
  • 突變:Relay 讓你使用 GraphQL 突變在用戶端和伺服器上突變資料,並提供自動資料一致性、樂觀更新和錯誤處理。

了解如何在自己的專案中使用 Relay.

GraphQL 要求

最後一次發布3 年前
星號6k
授權MIT 授權

一個簡單且彈性的 JavaScript GraphQL 用戶端,可以在所有 JavaScript 環境(瀏覽器、Node.js 和 React Native)中運作,基本上是一個輕量級的 fetch 包裝器。

AWS Amplify

最後一次發布19 小時前
星號9k
授權Apache License 2.0

一個用於使用雲端服務進行應用程式開發的 JavaScript 函式庫,支援 GraphQL 後端和 React 元件,以便處理 GraphQL 資料。

graphqurl

星號3k
授權Apache License 2.0

具有自動完成、訂閱和 GraphiQL 的 GraphQL 的 curl。也是一個非常簡單的通用 javascript GraphQL 用戶端。

GraphQL-WS

最後釋出1 個月前
星數2k
授權MIT 授權

一致、零依賴、延遲、簡單,符合 GraphQL over WebSocket 協定的伺服器和用戶端。

graphql-hooks

最後發布2 個月前
星數2k
授權其他

具備極小套件、SSR 支援和快取功能的最小 React hooks 優先 GraphQL 程式庫

  • 🥇 一流的 hooks API
  • ⚖️ 極小 套件:只有 7.6kB(gzip 壓縮後 2.8)
  • 📄 完整的 SSR 支援:請參閱 graphql-hooks-ssr
  • 🔌 外掛快取:請參閱 graphql-hooks-memcache
  • 🔥 不再有 render props 地獄
  • ⏳ 輕鬆處理載入和錯誤狀態

快速入門#

npm install graphql-hooks

首先,您需要建立一個客戶端並使用提供者包裝您的應用程式

import { GraphQLClient, ClientContext } from "graphql-hooks"
const client = new GraphQLClient({
url: "/graphql",
})
function App() {
return (
<ClientContext.Provider value={client}>
{/* children */}
</ClientContext.Provider>
)
}

現在,在您的子元件中,您可以使用 useQuery

import { useQuery } from "graphql-hooks"
const HOMEPAGE_QUERY = `query HomePage($limit: Int) {
users(limit: $limit) {
id
name
}
}`
function MyComponent() {
const { loading, error, data } = useQuery(HOMEPAGE_QUERY, {
variables: {
limit: 10,
},
})
if (loading) return "Loading..."
if (error) return "Something Bad Happened"
return (
<ul>
{data.users.map(({ id, name }) => (
<li key={id}>{name}</li>
))}
</ul>
)
}

Lokka

星數2k
授權MIT 授權

一個簡單的 JavaScript GraphQL 程式庫,可在所有 JavaScript 環境(瀏覽器、Node.js 和 React Native)中運作。

nanogql

星星422
授權MIT 授權

使用範本字串的極小 GraphQL 程式庫。

GraphQL-SSE

最後發布3 個月前
星星數362
授權MIT 授權

零相依性、HTTP/1 安全、簡單,透過伺服器傳送事件協定的 GraphQL 伺服器和用戶端。

GraphQL-HTTP

最後發布6 個月前
星星數272
授權MIT 授權

簡單、可插入、零相依性,符合 GraphQL over HTTP 規範的伺服器、用戶端和稽核套件。

graphql-ts-client

最後發布3 個月前
星星142
授權MIT 授權

適用於 TypeScript 的 GraphQL 程式庫,可根據強類型查詢請求自動推斷傳回資料的類型

GraphQLBox 程式庫

星星數23
授權MIT 授權

一個可擴充的 GraphQL 程式庫,具備 react、快取、請求剖析、網頁工作執行緒、網頁 socket 等模組...

以下範例會安裝和初始化 GraphQLBox 程式庫,並啟用持續快取和偵錯。

npm install @graphql-box/core @graphql-box/client @graphql-box/request-parser @graphql-box/cache-manager @graphql-box/debug-manager @graphql-box/fetch-manager @graphql-box/helpers @cachemap/core @cachemap/reaper @cachemap/indexed-db @cachemap/constants @cachemap/types
import Cachemap from "@cachemap/core"
import indexedDB from "@cachemap/indexed-db"
import reaper from "@cachemap/reaper"
import CacheManager from "@graphql-box/cache-manager"
import Client from "@graphql-box/client"
import DebugManager from "@graphql-box/debug-manager"
import FetchManager from "@graphql-box/fetch-manager"
import RequestParser from "@graphql-box/request-parser"
import introspection from "./introspection-query"
const requestManager = new FetchManager({
apiUrl: "/api/graphql",
batchRequests: true,
logUrl: "/log/graphql",
})
const client = new Client({
cacheManager: new CacheManager({
cache: new Cachemap({
name: "client-cache",
reaper: reaper({ interval: 300000 }),
store: indexedDB(/* configure */),
}),
cascadeCacheControl: true,
typeCacheDirectives: {
// Add any type specific cache control directives in the format:
// TypeName: "public, max-age=3",
},
}),
debugManager: new DebugManager({
environment: "client",
log: (message, data, logLevel) => {
requestManager.log(message, data, logLevel)
},
name: "CLIENT",
performance: self.performance,
}),
requestManager,
requestParser: new RequestParser({ introspection }),
})
// Meanwhile... somewhere else in your code
const { data, errors } = await client.request(queryOrMutation)

Grafoo

最後發布5 年前
星號274
授權MIT 授權

一個多功能 GraphQL 客戶端,僅需 1.6kb 即可與多個框架整合檢視層。

gq-loader

星號59
授權未知

一個簡單的 JavaScript GraphQL 客戶端,讓 *.gql 檔案可透過 webpack loader 作為模組使用。

工具

SpectaQL

星號1k
授權MIT 授權

SpectaQL 從 GraphQL 架構產生靜態 HTML 文件。

SpectaQL 是 Node.js 函式庫,使用各種選項為 GraphQL 架構產生靜態文件

  • 從使用內省查詢的即時端點。
  • 從包含內省查詢結果的檔案。
  • 從檔案、檔案或指向 SDL 中架構定義的 glob。

SpectaQL 會產生單一 3 欄 HTML 頁面,並讓您從幾個內建主題中選擇。此專案的主要目標是容易且高度自訂化,它可以設定主題,且幾乎所有內容都可以覆寫或自訂化。

npm install --dev spectaql
# OR
yarn add -D spectaql
# Then generate your docs
npm run spectaql my-config.yml
# OR
yarn spectaql my-config.yml

Postgraphile

最後發布5 個月前
星號12k
授權其他

在幾秒鐘內從 PostgreSQL 架構建置強大、可擴充且效能良好的 GraphQL API;為您節省數週甚至數個月的開發時間。

GraphQL 程式碼產生器

最後發布3 週前
星星數11k
授權MIT 授權

GraphQL 程式碼產生器,彈性支援自訂外掛程式和範本,例如 Typescript(前端和後端)、React Hooks、解析程式簽章等。

GraphQL 工具

最後釋出1 天前
星星數5k
授權MIT 授權

一組用於加速開發 GraphQL 工具的工具(Schema 和文件載入、Schema 合併等)。

GraphiQL

最後釋出2 週前
星星數16k
授權MIT 授權

一個互動式的瀏覽器內 GraphQL IDE。

GraphQLShield

最後發布1 年前
星星數4k
授權MIT 授權

一個 GraphQL 工具,用於簡化權限層的建立。

GraphQL Shield 可協助你為應用程式建立權限層。使用直覺式的規則 API,你可以在每個請求中獲得 shield 引擎的效能,並透過智慧快取減少每個請求的載入時間。這樣一來,你可以確保應用程式保持快速,且不會公開任何內部資料。

import { rule, shield, and, or, not } from "graphql-shield"
// Rules
const isAuthenticated = rule({ cache: "contextual" })(
async (parent, args, ctx, info) => {
return ctx.user !== null
}
)
const isAdmin = rule({ cache: "contextual" })(
async (parent, args, ctx, info) => {
return ctx.user.role === "admin"
}
)
const isEditor = rule({ cache: "contextual" })(
async (parent, args, ctx, info) => {
return ctx.user.role === "editor"
}
)
// Permissions
const permissions = shield({
Query: {
frontPage: not(isAuthenticated),
fruits: and(isAuthenticated, or(isAdmin, isEditor)),
customers: and(isAuthenticated, isAdmin),
},
Mutation: {
addFruitToBasket: isAuthenticated,
},
Fruit: isAuthenticated,
Customer: isAdmin,
})
// Server
const server = new GraphQLServer({
typeDefs,
resolvers,
middlewares: [permissions],
context: req => ({
...req,
user: getUser(req),
}),
})

GraphQL Scalars

最後發布2 天前
星數2k
授權MIT 授權

一個自訂 GraphQL scalar 類型的函式庫,用於建立精確、類型安全的 GraphQL schema。

GraphQL Modules

最後發布4 個月前
星號1k
授權MIT 授權

GraphQL Modules 讓您可以將後端實作區分成小型的、可重複使用的、易於實作和測試的區塊。

GraphQLMiddleware

最後發布8 個月前
星號1k
授權MIT 授權

將您的 GraphQL 解析器拆分為中間件函式。

GraphQL Middleware 是一個架構包裝器,讓您可以有效地管理多個解析器的額外功能。

功能#

💡 易於使用:直覺且熟悉的 API,您可以在一秒內上手。💪 強大:允許您完全控制解析器(之前、之後)。🌈 相容:適用於任何 GraphQL 架構。

範例#

const { ApolloServer } = require("apollo-server")
const { makeExecutableSchema } = require("@graphql-tools/schema")
const typeDefs = `
type Query {
hello(name: String): String
bye(name: String): String
}
`
const resolvers = {
Query: {
hello: (root, args, context, info) => {
console.log(`3. resolver: hello`)
return `Hello ${args.name ? args.name : "world"}!`
},
bye: (root, args, context, info) => {
console.log(`3. resolver: bye`)
return `Bye ${args.name ? args.name : "world"}!`
},
},
}
const logInput = async (resolve, root, args, context, info) => {
console.log(`1. logInput: ${JSON.stringify(args)}`)
const result = await resolve(root, args, context, info)
console.log(`5. logInput`)
return result
}
const logResult = async (resolve, root, args, context, info) => {
console.log(`2. logResult`)
const result = await resolve(root, args, context, info)
console.log(`4. logResult: ${JSON.stringify(result)}`)
return result
}
const schema = makeExecutableSchema({ typeDefs, resolvers })
const schemaWithMiddleware = applyMiddleware(schema, logInput, logResult)
const server = new ApolloServer({
schema: schemaWithMiddleware,
})
await server.listen({ port: 8008 })

GraphQL Mesh

最後發布3 分鐘前
星號3k
授權MIT 授權

GraphQL Mesh 讓您可以使用 GraphQL 查詢語言存取未執行 GraphQL 的遠端 API(以及執行 GraphQL 的 API)中的資料。它可用作其他服務的閘道,或作為一個本機 GraphQL 架構,從遠端 API 中彙總資料。

SOFA

最後發布2 個月前
星號1k
授權MIT 授權

從您的 GraphQL API 產生 REST API。

GraphQL Live Query

最後發布1 年前
星星431
授權MIT 授權

適用於任何 GraphQL 架構或傳輸的 GraphQL 即時查詢。

一個用於為 IDE 建立 GraphQL 語言服務的介面(診斷、自動完成等)。

GraphQL Inspector

最後發布3 個月前
星數2k
授權MIT 授權

比較架構、驗證文件、找出重大變更、找出類似類型、架構涵蓋範圍等。

GraphQL Config

最後發布5 個月前
星號1k
授權MIT 授權

一個用於所有 GraphQL 工具的設定(受大多數工具、編輯器和 IDE 支援)。

GraphQL-ESLint

最後發布6 個月前
星號1k
授權MIT 授權

GraphQL-ESLint 將 GraphQL AST 整合到 ESLint 核心(作為一個剖析器)。

GraphQL-HTTP

最後發布6 個月前
星星數272
授權MIT 授權

簡單、可插入、零相依性,符合 GraphQL over HTTP 規範的伺服器、用戶端和稽核套件。

Microfiber

星星30
授權MIT 授權

一個用於查詢和處理 GraphQL 內省查詢結果的函式庫。

Microfiber 是個 JavaScript 函式庫,允許

  • 針對特定查詢、突變、類型、欄位、引數或訂閱深入探討內省查詢結果。
  • 從內省查詢結果中移除特定查詢、突變、類型、欄位/輸入欄位、引數或訂閱。
  • 移除會參考不存在於內省查詢結果中(或已從其中移除)的類型的查詢、突變、欄位/輸入欄位或引數。
npm install microfiber
# OR
yarn add microfiber

然後在 JS 中

import { Microfiber } from 'microfiber'
const introspectionQueryResults = {...}
const microfiber = new Microfiber(introspectionQueryResults)
// ...do some things to your schema with `microfiber`
const cleanedIntrospectonQueryResults = microfiber.getResponse()

GraphQL CLI

最後一次發布3 年前
星數2k
授權MIT 授權

用於常見 GraphQL 開發工作流程的命令列工具。

GiraphQL

最後釋出2 週前
星數2k
授權ISC 授權

基於外掛程式架構的建構器,用於在 TypeScript 中建立優先撰寫程式碼的 GraphQL 架構

GiraphQL 簡化了撰寫類型安全架構,而且不需要程式碼產生器、建置程序或廣泛的手動類型定義。

import { ApolloServer } from "apollo-server"
import SchemaBuilder from "@giraphql/core"
const builder = new SchemaBuilder({})
builder.queryType({
fields: t => ({
hello: t.string({
args: {
name: t.arg.string({}),
},
resolve: (parent, { name }) => `hello, ${name || "World"}`,
}),
}),
})
new ApolloServer({
schema: builder.toSchema({}),
}).listen(3000)

Brangr

最後發布9 個月前
星號1
授權Mozilla Public License 2.0

瀏覽任何圖形 - 任何 GraphQL 服務的使用者友善檢視器

Brangr - Browse Any Graph

  • Brangr 是一個簡單、獨特的工具,任何網路伺服器都可以主機它,以提供任何 GraphQL 服務(或多個服務)的使用者友善瀏覽器/檢視器。

  • Brangr 以有吸引力的方式格式化 GraphQL 結果,透過使用者可自訂的版面配置選項。它讓使用者擷取產生的 HTML 及其來源 JSON。它提供一個聰明的架構瀏覽器。它有內建文件。

  • Brangr 讓主機它的網站能向使用者提供一系列預製的 GraphQL 要求,使用者可以根據需要編輯它們,並讓他們建立自己的要求。而且它允許網站為格式化結果的所有面向定義自訂 CSS 樣式。

  • 公開的 Brangr 網站上試試看。

範例

query {
heroes(_layout:{type:table}) { # _layout arg not sent to service
first
last
}
}

Brangr 顯示上述查詢如下(儘管不在引號區塊中)

英雄...
名字 姓氏
亞瑟丹特
福特 總管
柴法比布布洛克斯

伺服器

graphql-go

最後發布11 個月前
星號10k
授權MIT 授權

GraphQL 的 Go / Golang 實作。

99designs/gqlgen

最後發布1 週前
星號10k
授權MIT 授權

基於 Go 產生之 graphql 伺服器函式庫。

graph-gophers/graphql-go

最後發布1 年前
星星數5k
授權BSD 2 條款「簡化」授權

GraphQL 伺服器,專注於易用性。

samsarahq/thunder

星數2k
授權MIT 授權

GraphQL 實作,具備簡易的架構建置、即時查詢和批次處理功能。

graphql-go-tools

最後發布5 個月前
星號1k
授權MIT 授權

一系列用於建置 GraphQL 伺服器、閘道器、代理伺服器和 Go 中介軟體的工具。

graphql-go-tools 實作建置 GraphQL 伺服器、閘道器和代理伺服器的所有基本區塊。從詞法分析、解析、驗證、正規化,一直到查詢規劃和執行。

它也可以理解為 GraphQL 編譯器,具有新增您自己的後端的可能性。只需實現幾個介面,就能教導編譯器如何與任何後端對話 GraphQL。

以下後端已實現:GraphQL,支援 Apollo Federation/Supergraph。 資料庫:PostgreSQL、MySQL、SQLite、CockroachDB、MongoDB、SQLServer、OpenAPI/RESTKafka

若要了解如何實作新後端,請查看 靜態資料來源,因為它是其中最簡單的。

它已在許多企業的生產環境中使用多年,經過實戰考驗並積極維護。

graphql-relay-go

星星422
授權MIT 授權

一個 Go/Golang 函式庫,用於協助建構支援 react-relay 的 graphql-go 伺服器。

appointy/jaal

最後一次發布3 年前
星星76
授權MIT 授權

在 Go 中開發符合規範的 GraphQL 伺服器。

EGGQL

星星32
授權MIT 授權

易於使用、完整的 GraphQL Go 實作。簡單且無架構。

Eggql 的目的是讓建立 GraphQL 伺服器變得盡可能簡單。您不需要建立 GraphQL 架構(儘管有興趣的話,您可以檢視所建立的架構)。它目前處於測試版,但除了訂閱之外,它是 GraphQL 伺服器的完整實作。

為了清楚起見,它支援所有這些 GraphQL 功能:參數(包括預設值)、物件/清單/列舉/輸入/介面/聯合類型、別名、片段、變數、指令、突變、內嵌片段、描述、內省和自訂純量。

測試(jMeter)顯示,對於簡單的查詢,它比其他 Go 實作快或更快。我們正在進行效能的增強,包括快取、資料載入器、複雜度限制等。

若要執行 eggql hello world 伺服器,請建置並執行此 Go 程式

package main
import "github.com/andrewwphillips/eggql"
func main() {
http.Handle("/graphql", eggql.New(struct{ Message string }{Message: "hello, world"}))
http.ListenAndServe(":80", nil)
}

這會建立一個根查詢物件,並有一個 message 欄位。若要測試它,請使用 curl 傳送查詢

$ curl -XPOST -d '{"query": "{ message }"}' localhost:80/graphql

您會收到這個回應

{
"data": {
"message": "hello, world"
}
}

客戶端

genqlient

最後釋出2 週前
星號1k
授權MIT 授權

一個真正的型別安全 Go GraphQL 程式庫。

genqlient 是個 Go 程式庫,可輕鬆產生型別安全的程式碼,以查詢 GraphQL API。它利用 GraphQL 和 Go 都是型別語言的事實,以確保您的程式碼在編譯時執行有效的 GraphQL 查詢,並正確使用結果,所有這些都只需最少的樣板程式碼。

genqlient 提供

  • GraphQL 查詢的編譯時驗證:永遠不再傳送無效的 GraphQL 查詢!
  • 型別安全的回應物件:genqlient 為每個查詢產生正確的型別,因此您知道回應會正確地取消封送,而且永遠不需要使用 interface{}
  • 生產就緒:genqlient 在可汗學院用於生產,它支援全球數百萬的學習者和教師。

machinebox/graphql

最後發布5 年前
星號1k
授權Apache License 2.0

一個優雅的低階 HTTP 程式庫,用於 GraphQL。

graphql

星號1k
授權MIT 授權

一個 Go 中的 GraphQL 程式庫實作。

go-graphql-client

最後釋出2 週前
星星366
授權MIT 授權

一個支援突變、查詢和訂閱的 GraphQL Go 程式庫。

工具

graphjin

最後發布3 個月前
星號3k
授權Apache License 2.0

即時 GraphQL 至 SQL 編譯器。可用作獨立服務或 Go 函式庫。以前稱為 super-graph。

PHP

伺服器

API 平台

最後發布1 週前
星號8k
授權MIT 授權

API 平台是一個功能齊全、靈活且可擴充的 API 架構,建構於 Symfony 之上。

以下類別足以建立一個與 Relay 相容的 GraphQL 伺服器和支援現代 REST 格式(JSON-LD、JSONAPI...)的超媒體 API。

<?php
namespace AppEntity;
use ApiPlatformCoreAnnotationApiResource;
use DoctrineORMMapping as ORM;
/**
* Greet someone!
*
* @ApiResource
* @ORMEntity
*/
class Greeting
{
/**
* @ORMId
* @ORMColumn(type="guid")
*/
public $id;
/**
* @var string Your nice message
*
* @ORMColumn
*/
public $hello;
}

其他 API 平台功能包括資料驗證、驗證、授權、棄用、快取和 GraphiQL 整合。

graphql-php

最後發布1 週前
星星數5k
授權MIT 授權

GraphQL 參考實作的 PHP 移植

WPGraphQL

最新版本5 天前
星星數4k
授權GNU 通用公共授權條款第 3.0 版

一個免費的開源 WordPress 外掛程式,提供可擴充的 GraphQL 架構和 API 給任何 WordPress 網站

Lighthouse

最後發布1 週前
星號3k
授權MIT 授權

Laravel 的 GraphQL 伺服器

Siler

最後一次發布3 年前
星號1k
授權MIT 授權

Siler 是個 PHP 函式庫,具備高階抽象功能,可處理 GraphQL。

執行 Siler hello world 腳本

type Query {
hello: String
}
<?php
declare(strict_types=1);
require_once '/path/to/vendor/autoload.php';
use SilerDiactoros;
use SilerGraphql;
use SilerHttp;
$typeDefs = file_get_contents(__DIR__.'/schema.graphql');
$resolvers = [
'Query' => [
'hello' => 'world',
],
];
$schema = Graphqlschema($typeDefs, $resolvers);
echo "Server running at http://127.0.0.1:8080";
Httpserver(Graphqlpsr7($schema), function (Throwable $err) {
var_dump($err);
return Diactorosjson([
'error' => true,
'message' => $err->getMessage(),
]);
})()->run();

它還提供功能,用於建置 WebSocket 訂閱伺服器,其運作方式基於 Apollo。

GraphQLBundle

最後發布1 週前
星號1k
授權MIT 授權

Symfony 的 GraphQL 伺服器

GraphQLite

最新版本12 小時前
星號1k
授權MIT 授權

GraphQLite 是一個提供基於註解語法的 GraphQL 結構定義的函式庫。

它與框架無關,並提供 Symfony 和 Laravel 的繫結。此程式碼宣告一個「產品」查詢和一個「產品」類型

class ProductController
{
/**
* @Query()
*/
public function product(string $id): Product
{
// Some code that looks for a product and returns it.
}
}
/**
* @Type()
*/
class Product
{
/**
* @Field()
*/
public function getName(): string
{
return $this->name;
}
// ...
}

其他 GraphQLite 功能包括驗證、安全性、錯誤處理、透過資料載入器模式載入...

Railt

最後發布5 年前
星號360
授權MIT 授權

一個 PHP GraphQL 框架。

Gato GraphQL

最新版本6 天前
星號348
授權GNU 通用公共授權條款第 2.0 版

與 WordPress 中的所有資料互動

graphql-relay-php

最新版本2 年前
星號271
授權BSD 3 條款「新」或「修訂」授權

一個協助建構支援 react-relay 的 graphql-php 伺服器的函式庫。

GraPHPinator

最後發布4 個月前
星號39
授權MIT 授權

一個適用於現代 PHP 的 GraphQL 實作。包含最新草案中的功能、中間軟體指令和具有額外功能的模組。

GraPHPinator 是 GraphQL 伺服器的功能完備 PHP 實作。它的工作是將查詢字串轉換為給定結構的已解析 Json 結果。

  • 目標是符合 GraphQL 規格的最新草案。
  • 完全類型安全,因此最低要求的 PHP 版本為 8.0。為了大量的清晰度和安全性而犧牲了一點便利性 - 沒有隨機配置的陣列、沒有混合類型、沒有變數函式引數 - 這個函式庫不會試圖讓您免於冗長,但會確保您始終知道自己擁有的內容。
  • 先編寫程式碼。
  • 靈活。使用模組或中間軟體指令輕鬆擴充額外功能。
  • 包含一些選擇加入的擴充功能,這些功能不在官方規格範圍內
    • 印表機 - GraPHPinator 型別系統的架構列印。
    • 額外型別 - 一些有用且常用的型別,包括標量或複合型別。
    • 約束指令 - 型別系統指令,用於在 GraphQL 型別系統之上宣告額外的驗證。
    • where 指令 - 可執行的指令,用於過濾清單中的值。
    • 使用 multipart-formdata 規格(目前已綑綁)上傳檔案。
    • 查詢成本限制模組 - 模組,用於透過限制最大深度或節點數來限制查詢成本。
  • 專案由多個較小的套件組成,這些套件可以獨立使用
    • 分詞器 - GraphQL 文件的語法分析器。
    • 剖析器 - GraphQL 文件的語法分析器。

serge

星星5
授權GNU 通用公共授權條款第 3.0 版

使用 GraphQL 為 CQRS/ES 定義您的網域模型,並讓 serge 產生程式碼來處理 GraphQL 要求。

Java / Kotlin

伺服器

graphql-java

最後釋出1 天前
星號6k
授權MIT 授權

用於建置 GraphQL API 的 Java 函式庫。

請參閱 GraphQL Java 網站上的 入門教學

使用 graphql-java 執行 hello world GraphQL 查詢的程式碼

import graphql.ExecutionResult;
import graphql.GraphQL;
import graphql.schema.GraphQLSchema;
import graphql.schema.StaticDataFetcher;
import graphql.schema.idl.RuntimeWiring;
import graphql.schema.idl.SchemaGenerator;
import graphql.schema.idl.SchemaParser;
import graphql.schema.idl.TypeDefinitionRegistry;
import static graphql.schema.idl.RuntimeWiring.newRuntimeWiring;
public class HelloWorld {
public static void main(String[] args) {
String schema = "type Query{hello: String}";
SchemaParser schemaParser = new SchemaParser();
TypeDefinitionRegistry typeDefinitionRegistry = schemaParser.parse(schema);
RuntimeWiring runtimeWiring = newRuntimeWiring()
.type("Query", builder -> builder.dataFetcher("hello", new StaticDataFetcher("world")))
.build();
SchemaGenerator schemaGenerator = new SchemaGenerator();
GraphQLSchema graphQLSchema = schemaGenerator.makeExecutableSchema(typeDefinitionRegistry, runtimeWiring);
GraphQL build = GraphQL.newGraphQL(graphQLSchema).build();
ExecutionResult executionResult = build.execute("{hello}");
System.out.println(executionResult.getData().toString());
// Prints: {hello=world}
}
}

請參閱 graphql-java 文件 以取得更多資訊。

Domain Graph Service (DGS) Framework

最後釋出1 天前
星號3k
授權Apache License 2.0

DGS Framework (Domain Graph Service) 是由 Netflix 開發的 Spring Boot GraphQL 伺服器框架。

DGS Framework (Domain Graph Service) 是由 Netflix 開發的 Spring Boot GraphQL 伺服器框架。

功能包括

  • 基於註解的 Spring Boot 程式設計模型
  • 用於撰寫查詢測試作為單元測試的測試框架
  • Gradle 程式碼產生外掛程式,用於從架構建立類型
  • 輕鬆與 GraphQL Federation 整合
  • 與 Spring Security 整合
  • GraphQL 訂閱 (WebSockets 和 SSE)
  • 檔案上傳
  • 錯誤處理
  • 許多擴充功能

請參閱 DGS Framework 入門 以了解如何開始使用。

graphql-kotlin

最後釋出1 個月前
星數2k
授權Apache License 2.0

一組用於在 Kotlin 中執行 GraphQL 伺服器和用戶端的函式庫。

GraphQL Kotlin 採用程式碼優先的方法來產生您的 GraphQL 架構。由於 Kotlin 和 GraphQL 之間的相似性,例如定義可為空/不可為空類型的能力,因此可以從 Kotlin 程式碼產生架構,而不需要任何獨立的架構規格。若要建立一個反應式 GraphQL 網路伺服器,請將下列相依性加入您的 Gradle 建置檔案

// build.gradle.kts
implementation("com.expediagroup", "graphql-kotlin-spring-server", latestVersion)

我們還需要提供一個支援套件清單,可以透過反射掃描來公開您的架構物件。將下列組態加入您的 application.yml 檔案

graphql:
packages:
- "com.your.package"

透過上述組態,我們現在可以建立我們的架構。若要公開您的查詢、變異和/或訂閱在 GraphQL 架構中,您只需要實作對應的標記介面,它們將會自動由 graphql-kotlin-spring-server 自動組態函式庫擷取。

@Component
class HelloWorldQuery : Query {
fun helloWorld() = "Hello World!!!"
}

這將會產生一個具有下列架構的反應式 GraphQL 網路應用程式

type Query {
helloWorld: String!
}

請參閱 graphql-kotlin 文件 以取得更多詳細資料。

GraphQL Spring Boot

最後發布3 個月前
星數2k
授權MIT 授權

來自 GraphQL Java Kickstart 的 GraphQL Spring Boot

GraphQL Spring Boot 會將任何 Spring Boot 應用程式轉換成 GraphQL 伺服器

已啟動的應用程式包含以下功能

請參閱 GraphQL Java Kickstart 入門 以了解如何入門。

Spring for GraphQL

最新版本4 週前
星號1k
授權Apache License 2.0

Spring for GraphQL 提供對建構在 GraphQL Java 上的 Spring 應用程式的支援。

Spring for GraphQL 提供對建構在 GraphQL Java 上的 Spring 應用程式的支援。請參閱官方 Spring 指南 以了解如何在 15 分鐘內建構 GraphQL 服務。

  • 這是 GraphQL Java 團隊和 Spring 工程之間的共同合作。
  • 我們共同的理念是提供最少的意見,同時專注於對廣泛使用案例提供全面的支援。
  • 它旨在成為所有 Spring、GraphQL 應用程式的基礎。

功能

  • 透過 HTTP、WebSocket 和 RSocket 處理 GraphQL 要求的伺服器。
  • 基於註解的程式設計模型,其中 @Controller 元件使用註解來宣告處理方法,並使用彈性的方法簽章來擷取特定 GraphQL 欄位的資料。例如
@Controller
public class GreetingController {
@QueryMapping
public String hello() {
return "Hello, world!";
}
}
  • 透過 HTTP、WebSocket 和 RSocket 執行 GraphQL 要求的用戶端支援。
  • 專門支援透過 HTTP、WebSocket 和 RSocket 測試 GraphQL 要求,以及直接針對伺服器進行測試。

若要開始使用,請查看 https://start.spring.io 上的 Spring GraphQL starter 和此儲存庫中的 範例

Jimmer

最後發布1 週前
星號1k
授權Apache License 2.0

一個適用於 Java 和 Kotlin 的革命性 ORM 框架,它還提供專門的 API,用於快速開發基於 Spring GraphQL 的應用程式。

介紹#

  1. 自 2.7 版起,SpringBoot 引入了 Spring GraphQL。Jimmer 提供專門的 API,用於快速開發基於 Spring GraphQL 的應用程式。

  2. 支援兩種 API:Java API 和 Kotlin API。

  3. 強大且友善的 GraphQL 快取支援。

  4. 比其他熱門的 ORM 解决方案更快,請參閱基準:https://babyfish-ct.github.io/jimmer/docs/benchmark/

  5. 比其他熱門的 ORM 解决方案更強大。

    ORM 設計中應考慮三個方面

    a. 查詢。b. 更新。c. 快取。

    每個方面都針對具有任意深度的物件樹,而不是簡單的物件。這種獨特設計帶來了其他熱門解决方案無法比擬的便利性。

連結#

KGraphQL

最後發布1 年前
星星292
授權MIT 授權

KGraphQL 是 GraphQL 的 Kotlin 實作。它提供豐富的 DSL 來設定 GraphQL 架構。

以下是一個範例,說明如何根據 Kotlin 資料類別建立簡單的架構,以及套用至類別的屬性解析器。

data class Article(val id: Int, val text: String)
fun main() {
val schema = KGraphQL.schema {
query("article") {
resolver { id: Int?, text: String ->
Article(id ?: -1, text)
}
}
type<Article> {
property<String>("fullText") {
resolver { article: Article ->
"${article.id}: ${article.text}"
}
}
}
}
schema.execute("""
{
article(id: 5, text: "Hello World") {
id
fullText
}
}
""").let(::println)
}

KGraphQL 在幕後使用協程,提供絕佳的非同步效能。

請參閱 KGraphQL 文件,深入了解用法。

Ktor 外掛#

KGraphQL 有 Ktor 外掛,只要呼叫 install 函式,就能提供功能齊全的 GraphQL 伺服器。以下範例說明如何在 Ktor 中設定 GraphQL 伺服器,輸入 localhost:8080/graphql,就能立即取得 GraphQL Playground

fun Application.module() {
install(GraphQL) {
playground = true
schema {
query("hello") {
resolver { -> "World!" }
}
}
}
}

您可以遵循 Ktor 教學,從頭開始使用 ktor 設定 KGraphQL 伺服器。

graphql-calculator

最新版本2 年前
星號103
授權Apache License 2.0

輕量級 graphql 計算引擎。

GraphQL Calculator 是一款輕量級 graphql 計算引擎,用於變更 graphql 查詢的執行行為。

以下是一些在 graphql 查詢中使用 GraphQL Calculator 的範例。

query basicMapValue($userIds: [Int]) {
userInfoList(userIds: $userIds) {
id
age
firstName
lastName
fullName: stringHolder @map(mapper: "firstName + lastName")
}
}
query filterUserByAge($userId: [Int]) {
userInfoList(userIds: $userId) @filter(predicate: "age>=18") {
userId
age
firstName
lastName
}
}
query parseFetchedValueToAnotherFieldArgumentMap($itemIds: [Int]) {
itemList(itemIds: $itemIds) {
# save sellerId as List<Long> with unique name "sellerIdList"
sellerId @fetchSource(name: "sellerIdList")
name
saleAmount
salePrice
}
userInfoList(userIds: 1)
# transform the argument of "userInfoList" named "userIds" according to expression "sellerIdList" and expression argument,
# which mean replace userIds value by source named "sellerIdList"
@argumentTransform(
argumentName: "userIds"
operateType: MAP
expression: "sellerIdList"
dependencySources: ["sellerIdList"]
) {
userId
name
age
}
}

請參閱 graphql-calculator README,取得更多資訊。

MicroProfile GraphQL

最新版本2 年前
星星95
授權Apache License 2.0

MP GraphQL 是一種優先考慮程式碼的規格,用於建置 GraphQL 應用程式。它使用類似於 JAX-RS 的註解和設計模式,以實現快速開發。

MicroProfile GraphQL 是一種 GraphQL 伺服器和用戶端規格,用於建置 GraphQL 應用程式。它獨特的基於註解的 API 方法可實現快速應用程式開發。編寫成 MP GraphQL API 的應用程式是可攜式的,且可以部署到 Java 伺服器執行時期,例如 Open LibertyQuarkusHelidonWildfly。這表示您的應用程式可以使用其他 JakartaMicroProfile 技術。

MP GraphQL 功能包括

  • 基於註解的 API
  • 與 Jakarta CDI 整合
  • 類型安全和動態用戶端 API
  • 例外處理
  • 與 Jakarta 和 MicroProfile 技術輕鬆整合

想要開始嗎?查看這些資源

或這些影片

客戶端

Apollo Kotlin

最後一次發布58 分鐘前
星星數4k
授權MIT 授權

JVM、Android 和 Kotlin 多平台的強類型快取 GraphQL 客户端。

Apollo Kotlin(以前稱為 Apollo Android)是一款 GraphQL 客户端,支援 Android、Java8+、iOS 和一般 Kotlin 多平台。其特色包括

  • Java 和 Kotlin 多平台程式碼產生
  • 查詢、變異和訂閱
  • 無反射解析
  • 正規化快取
  • 自訂標量類型
  • HTTP 快取
  • 自動持久查詢
  • 查詢批次處理
  • 檔案上傳
  • Espresso IdlingResource
  • 測試用假模型
  • AppSync 和 graphql-ws 網路套接字
  • GraphQL AST 解析器

graphql-kotlin

最後釋出1 個月前
星數2k
授權Apache License 2.0

一組用於在 Kotlin 中執行 GraphQL 伺服器和用戶端的函式庫。

GraphQL Kotlin 提供一組輕量級且類型安全的 GraphQL HTTP 客户端。此函式庫提供 Ktor HTTP 客户端和 Spring WebClient 為基礎的參考實作,並允許使用其他引擎進行自訂實作。Jackson 和 kotlinx-serialization 類型安全資料模型會在建置時由提供的 Gradle 和 Maven 外掛產生。

若要產生將與 GraphQL Kotlin Spring WebClient 一起使用的 Jackson 模型,請將下列內容新增到 Gradle 建置檔案

// build.gradle.kts
import com.expediagroup.graphql.plugin.gradle.graphql
plugins {
id("com.expediagroup.graphql") version $latestGraphQLKotlinVersion
}
dependencies {
implementation("com.expediagroup:graphql-kotlin-spring-client:$latestGraphQLKotlinVersion")
}
graphql {
client {
// target GraphQL endpoint
endpoint = "http://localhost:8080/graphql"
// package for generated client code
packageName = "com.example.generated"
}
}

預設情況下,GraphQL Kotlin 外掛會在 src/main/resources 下尋找查詢檔案。假設有 HelloWorldQuery.graphql 範例查詢

query HelloWorldQuery {
helloWorld
}

外掛會產生實作 GraphQLClientRequest 介面的簡單 POJO 類別,並表示 GraphQL 要求。

package com.example.generated
import com.expediagroup.graphql.client.types.GraphQLClientRequest
import kotlin.String
import kotlin.reflect.KClass
const val HELLO_WORLD_QUERY: String = "query HelloWorldQuery {\n helloWorld\n}"
class HelloWorldQuery: GraphQLClientRequest<HelloWorldQuery.Result> {
override val query: String = HELLO_WORLD_QUERY
override val operationName: String = "HelloWorldQuery"
override fun responseType(): KClass<HelloWorldQuery.Result> = HelloWorldQuery.Result::class
data class Result(
val helloWorld: String
}
}

然後,我們可以使用目標客户端執行我們的查詢。

package com.example.client
import com.expediagroup.graphql.client.spring.GraphQLWebClient
import com.expediagroup.graphql.generated.HelloWorldQuery
import kotlinx.coroutines.runBlocking
fun main() {
val client = GraphQLWebClient(url = "http://localhost:8080/graphql")
runBlocking {
val helloWorldQuery = HelloWorldQuery()
val result = client.execute(helloWorldQuery)
println("hello world query result: ${result.data?.helloWorld}")
}
}

請參閱 graphql-kotlin 客户端文件 以取得更多詳細資訊。

節點

最後一次發布4 年前
星星305
授權Apache License 2.0

由 American Express 設計的 GraphQL JVM 客户端,用于从标准模型定义构建查询。

工具

GraphQL Java Generator

星星50
授權MIT 授權

GraphQL Java Generator 是一款工具,可生成 Java 代码,以加快 GraphQL API 客户端和服务器的开发速度

  • GraphQL Java 客户端:它生成调用 GraphQL 端点的 Java 类,以及将包含服务器返回数据的 POJO。然后,可以通过对 Java 方法的简单调用来查询 GraphQL 端点(请参阅下面的示例)
  • GraphQL Java 服务器:它基于 graphql-java(上面列出)。它生成所有样板代码。您只需要实现特定于服务器的内容,即 GraphQL 类型之间的联接。GraphQL Java Generator 可作为 Maven 插件 提供。Gradle 插件即将推出。请注意,GraphQL Java Generator 是一款加速器:生成的代码不依赖于任何特定于 GraphQL Java Generator 的库。因此,它可以帮助您开始构建基于 graphql-java 的应用程序。生成代码后,您可以决定像任何标准 Java 应用程序一样手动编辑它,并摆脱 GraphQL Java Generator。当然,您可以(并且应该)根据我们的建议 :) 在您的项目发展时继续使用 GraphQL Java Generator。

C# / .NET

伺服器

graphql-dotnet

最後釋出1 個月前
星號6k
授權MIT 授權

GraphQL for .NET

using System;
using System.Threading.Tasks;
using GraphQL;
using GraphQL.Types;
using GraphQL.SystemTextJson; // First add PackageReference to GraphQL.SystemTextJson
public class Program
{
public static async Task Main(string[] args)
{
var schema = Schema.For(@"
type Query {
hello: String
}
");
var json = await schema.ExecuteAsync(_ =>
{
_.Query = "{ hello }";
_.Root = new { Hello = "Hello World!" };
});
Console.WriteLine(json);
}
}

Hot Chocolate

最後一次發布3 小時前
星星數5k
授權MIT 授權

Hot Chocolate 是 .NET 的開源 GraphQL 伺服器

Hot Chocolate 消除了建構一個成熟 GraphQL 伺服器的複雜性,讓您可以專注於提供下一個重大功能。

using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
WebHost
.CreateDefaultBuilder(args)
.ConfigureServices(services =>
services
.AddGraphQLServer()
.AddQueryType<Query>())
.Configure(builder =>
builder
.UseRouting()
.UseEndpoints(e => e.MapGraphQL()))
.Build()
.Run();
public class Query
{
public Hero GetHero() => new Hero();
}
public class Hero
{
public string Name => "Luke Skywalker";
}

graphql-net

星號1k
授權MIT 授權

將 GraphQL 轉換為 IQueryable

Entity GraphQL

最後釋出1 天前
星號373
授權MIT 授權

.NET Core 的 GraphQL 函式庫。輕鬆地將您的資料模型公開為 GraphQL API,或將多個資料來源匯集到單一 GraphQL 架構中。

// expose an exisiting data model with ASP.NET & EF Core
public class Startup {
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<DemoContext>();
// Auto build a schema from DemoContext. Alternatively you can build one from scratch
services.AddGraphQLSchema<DemoContext>(options =>
{
// modify the schema (add/remove fields or types), add other services
});
}
public void Configure(IApplicationBuilder app, DemoContext db)
{
app.UseRouting();
app.UseEndpoints(endpoints =>
{
// defaults to /graphql endpoint
endpoints.MapGraphQL<DemoContext>();
});
}
}

一組用於在 .NET 中實作高性能 GraphQL 伺服器的套件。忠實實作官方 2018 年規格。具備批次執行支援(又稱資料載入器);支援自訂標量;基於 ASP.NET Core 的 HTTP 伺服器;已剖析的查詢快取;模組化 API 建構(等同於架構縫合);完整的內省支援;執行時期指標和配額。

客戶端

Strawberry Shake

最後一次發布3 小時前
星星數5k
授權MIT 授權

Strawberry Shake 是 .NET 的開源反應式 GraphQL 客戶端

Strawberry Shake 消除了狀態管理的複雜性,讓您可以透過 GraphQL 與本機和遠端資料進行互動。

您可以使用 Strawberry Shake 來

  • 從您的 GraphQL 查詢產生 C# 客戶端。
  • 透過 GraphQL 與本機和遠端資料進行互動。
  • 使用反應式 API 與您的狀態進行互動。
client.GetHero
.Watch(ExecutionStrategy.CacheFirst)
.Subscribe(result =>
{
Console.WriteLine(result.Data.Name);
})

GraphQL.Client

最新版本5 小時前
星號1k
授權MIT 授權

適用於 .NET 的 GraphQL 客戶端。

ZeroQL

最新版本4 週前
星星236
授權MIT 授權

ZeroQL 是適用於 C# 的開源 GraphQL 客戶端

ZeroQL 是一款效能良好的 C# 友善 GraphQL 客戶端。它支援類似 Linq 的語法,且不需要 Reflection.Emit 或表達式。因此,在執行階段提供的效能非常接近原始 HTTP 呼叫。

你可以使用 ZeroQL 來

  • 從 GraphQL 架構產生 C# 客戶端。
  • 從你的 C# 程式碼產生並執行 graphql 查詢。
  • 不需要手動撰寫 GraphQL。
  • 支援 .Net Core、.Net Framework、Xamarin、Unity 應用程式。
var userId = 10;
var response = await qlClient.Query(q => q
.User(userId, o => new
{
o.Id,
o.FirstName,
o.LastName
}));

適用於 .NET 的基本範例 GraphQL 客戶端。

SAHB.GraphQLClient

最後一次發布3 年前
星星43
授權MIT 授權

支援從 C# 類別產生查詢的 GraphQL 客戶端

伺服器

Graphene

最新版本7 個月前
星號8k
授權MIT 授權

用於建置 GraphQL API 的 Python 程式庫。

若要執行 Graphene hello world 腳本

pip install graphene

然後在 hello.py 中執行 python hello.py,其中包含此程式碼

import graphene
class Query(graphene.ObjectType):
hello = graphene.String(name=graphene.String(default_value="World"))
def resolve_hello(self, info, name):
return 'Hello ' + name
schema = graphene.Schema(query=Query)
result = schema.execute('{ hello }')
print(result.data['hello']) # "Hello World"

也有適用於 Relay、Django、SQLAlchemy 和 Google App Engine 的良好繫結。

Strawberry

最後發布1 週前
星星數4k
授權MIT 授權

Strawberry 是 Python 程式庫,用於使用現代 Python 功能(例如類型提示)實作優先考慮程式碼的 GraphQL 伺服器。

以下是 Strawberry hello world 的範例,首先安裝程式庫

pip install strawberry-graphql

建立一個內容為以下的 app.py 檔案

import strawberry
@strawberry.type
class Query:
@strawberry.field
def hello(self, name: str = "World") -> str:
return f"Hello {name}"
schema = strawberry.Schema(query=Query)

然後執行 strawberry server app,你將會在 http://localhost:8000/ 上執行一個基本的架構伺服器。

Strawberry 也有針對 ASGI、Flask 和 Django 的檢視,並提供資料載入器和追蹤等工具。

Ariadne

最後發布2 天前
星數2k
授權BSD 3 條款「新」或「修訂」授權

Ariadne 是使用架構優先方式實作 GraphQL 伺服器的 Python 函式庫。它支援同步和非同步查詢執行,內建常見的 GraphQL 伺服器問題解決方案,例如查詢成本驗證或效能追蹤,並具備易於延伸或替換的簡單 API。

Ariadne 可透過 pip 安裝

$ pip install ariadne

最小的「Hello world」伺服器範例

from ariadne import ObjectType, gql, make_executable_schema
from ariadne.asgi import GraphQL
type_defs = gql(
"""
type Query {
hello: String!
}
"""
)
query_type = ObjectType("Query")
@query_type.field("hello")
def resolve_hello(*_):
return "Hello world!"
schema = make_executable_schema(type_defs, query_type)
app = GraphQL(schema, debug=True)

使用 uvicorn 執行伺服器

$ pip install uvicorn
$ uvicorn example:app

Tartiflette

最新版本2 年前
星號1k
授權MIT 授權

用於建立 GraphQL API 的 Python 3.6+ (asyncio) 函式庫。

執行 tartiflette hello world 腳本

pip install tartiflette

然後在 hello.py 中執行 python hello.py,其中包含此程式碼

import asyncio
from tartiflette import Engine, Resolver
@Resolver("Query.hello")
async def resolver_hello(parent, args, ctx, info):
return "hello " + args["name"]
async def run():
tftt_engine = Engine("""
type Query {
hello(name: String): String
}
""")
result = await tftt_engine.execute(
query='query { hello(name: "Chuck") }'
)
print(result)
# {'data': {'hello': 'hello Chuck'}}
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.run_until_complete(run())

還有一個不錯的 HTTP 包裝器

Django Graphbox

最後發布2 個月前
星星9
授權MIT 授權

使用 Django 模型的基本 CRUD 操作輕鬆建立 GraphQL API 的套件。

Django Graphbox 快速入門

  1. 安裝套件
pip install django-graphbox
  1. 建立新的 Django 專案
django-admin startproject myproject
  1. 建立新的 Django 應用程式
cd myproject
python manage.py startapp myapp
  1. myapp/models.py 中定義 Django 模型
from django.db import models
class MyModel(models.Model):
name = models.CharField(max_length=100)
  1. 建立並執行遷移
python manage.py makemigrations
python manage.py migrate
  1. myapp/schema.py 中設定並建立 GraphQL 架構
from django_graphbox.builder import SchemaBuilder
from myapp.models import MyModel
builder = SchemaBuilder()
builder.add_model(MyModel)
query_class = builder.build_schema_query()
mutation_class = builder.build_schema_mutation()
  1. myproject/schema.py 中建立一個主架構(你可以在這個主架構中新增自己的查詢和突變)
import graphene
from myapp.schema import query_class, mutation_class
class Query(query_class, graphene.ObjectType):
pass
class Mutation(mutation_class, graphene.ObjectType):
pass
schema = graphene.Schema(query=Query, mutation=Mutation)
  1. myproject/urls.py 中新增 GraphQL 檢視
from django.urls import path
from graphene_file_upload.django import FileUploadGraphQLView
from django.views.decorators.csrf import csrf_exempt
from myproject.schema import schema
urlpatterns = [
path('graphql/', csrf_exempt(FileUploadGraphQLView.as_view(graphiql=True, schema=schema))),
]
  1. 執行伺服器
python manage.py runserver
  1. http://localhost:8000/graphql/ 開啟 GraphiQL 介面,開始查詢您的 API

您可以在 github 或 pypi 上找到進階範例,包含驗證、過濾器、驗證等。

客戶端

GQL

最後釋出1 個月前
星號1k
授權MIT 授權

Python 中的 GraphQL 程式庫。

sgqlc

星星491
授權ISC 授權

一個簡單的 Python GraphQL 程式庫。支援為 GraphQL 架構中定義的類型產生程式碼。

Ariadne Codegen

最後釋出2 週前
星星193
授權BSD 3 條款「新」或「修訂」授權

從任何架構和查詢產生完全型別的 Python GraphQL 程式庫。

安裝 Ariadne Codegen

$ pip install ariadne-codegen

建立 queries.graphql 檔案

mutation CreateToken($username: String!, $password: String!) {
createToken(username: $username, password: $password) {
token
errors {
field
message
}
}
}

在您的 pyproject.toml 中加入 [ariadne-codegen] 區段

[ariadne-codegen]
queries_path = "queries.graphql"
remote_schema_url = "http://example.com/graphql/"

產生程式庫

$ ariadne-codegen

並在您的 Python 專案中使用它

from graphql_client import Client
with Client("http://example.com/graphql/") as client:
result = client.create_token(username="Admin", password="Example123)
if result.errors:
error = result.errors[0]
raise ValidationError({error.field: error.message})
auth_token = result.token

Python 2.7+ 的簡單 GraphQL 程式庫。

Qlient

最後發布1 年前
星星45
授權MIT 授權

一個快速且現代的 graphql 程式庫,以簡潔為設計理念。

以下是 qlient hello world 的範例。

首先安裝函式庫

pip install qlient

建立一個包含以下內容的 swapi_client_example.py 檔案

from qlient.http import HTTPClient, GraphQLResponse
client = HTTPClient("https://swapi-graphql.netlify.app/.netlify/functions/index")
res: GraphQLResponse = client.query.film(
# swapi graphql input fields
id="ZmlsbXM6MQ==",
# qlient specific
_fields=["id", "title", "episodeID"]
)
print(res.request.query) # query film($id: ID) { film(id: $id) { id title episodeID } }
print(res.request.variables) # {'id': 'ZmlsbXM6MQ=='}
print(res.data) # {'film': {'id': 'ZmlsbXM6MQ==', 'title': 'A New Hope', 'episodeID': 4}}

關閉檔案並使用 python 執行它

python swapi_client_example.py

graphql-query

最新版本4 週前
星星45
授權MIT 授權

完整的 Python GraphQL 查詢字串產生器。

graphql_query 是 python 的完整 GraphQL 查詢字串產生器。使用 graphql_query,您可以 graphql_query 的文件可以在 https://denisart.github.io/graphql-query/ 找到。

$ pip install graphql_query

簡單查詢的程式碼

{
hero {
name
}
}

from graphql_query import Operation, Query
hero = Query(name="hero", fields=["name"])
operation = Operation(type="query", queries=[hero])
print(operation.render())
"""
query {
hero {
name
}
}
"""

用於產生以下查詢

query Hero($episode: Episode, $withFriends: Boolean!) {
hero(episode: $episode) {
name
friends @include(if: $withFriends) {
name
}
}
}

我們有

from graphql_query import Argument, Directive, Field, Operation, Query, Variable
episode = Variable(name="episode", type="Episode")
withFriends = Variable(name="withFriends", type="Boolean!")
arg_episode = Argument(name="episode", value=episode)
arg_if = Argument(name="if", value=withFriends)
hero = Query(
name="hero",
arguments=[arg_episode],
fields=[
"name",
Field(
name="friends",
fields=["name"],
directives=[Directive(name="include", arguments=[arg_if])]
)
]
)
operation = Operation(
type="query",
name="Hero",
variables=[episode, withFriends],
queries=[hero]
)
print(operation.render())
"""
query Hero(
$episode: Episode
$withFriends: Boolean!
) {
hero(
episode: $episode
) {
name
friends @include(
if: $withFriends
) {
name
}
}
}
"""

伺服器

graphql-rust/juniper

最後發布1 小時前
星號6k
授權其他

Rust 的 GraphQL 伺服器程式庫

Async-graphql

最後發布1 年前
星號3k
授權Apache License 2.0

Async-graphql 是一個效能高的伺服器端程式庫,支援所有 GraphQL 規範。

use async_graphql::*;
struct Query;
#[Object]
impl Query {
/// Returns the sum of a and b
async fn add(&self, a: i32, b: i32) -> i32 {
a + b
}
}

客戶端

cynic

最後釋出1 個月前
星星333
授權Mozilla Public License 2.0

Rust 的自備類型 GraphQL 客戶端

Rust 的客戶端程式庫,從您提供的類型產生查詢,驗證類型是否與您的架構形狀相符。

它提供 一個產生器,從現有的 GraphQL 查詢引導類型。

使用範例

#[derive(cynic::QueryFragment, Debug)]
#[cynic(
schema_path = "../schemas/starwars.schema.graphql",
query_module = "query_dsl",
graphql_type = "Root",
argument_struct = "FilmArguments"
)]
struct FilmDirectorQuery {
#[arguments(id = &args.id)]
film: Option<Film>,
}
#[derive(cynic::QueryFragment, Debug)]
#[cynic(
schema_path = "../schemas/starwars.schema.graphql",
query_module = "query_dsl",
graphql_type = "Film"
)]
struct Film {
title: Option<String>,
director: Option<String>,
}
#[derive(cynic::FragmentArguments)]
struct FilmArguments {
id: Option<cynic::Id>,
}
fn main() {
use cynic::{QueryBuilder, http::ReqwestBlockingExt};
let query = FilmDirectorQuery::build(&FilmArguments {
id: Some("ZmlsbXM6MQ==".into()),
})
reqwest::blocking::Client::new()
.post("https://swapi-graphql.netlify.com/.netlify/functions/index")
.run_graphql(query)
.unwrap()
}
mod query_dsl {
cynic::query_dsl!("../schemas/starwars.schema.graphql");
}

gql_client

星星47
授權MIT 授權

Rust 的最小 GraphQL 客戶端

使用範例

use gql_client::Client;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let endpoint = "https://graphqlzero.almansi.me/api";
let query = r#"
query AllPostsQuery {
posts {
data {
id
}
}
}
"#;
let client = Client::new(endpoint);
let data: AllPosts = client.query::<AllPosts>(query).await.unwrap();
println!("{:?}" data);
Ok(())
}

Ruby

伺服器

graphql-ruby

最後一次發布3 年前
星星數5k
授權MIT 授權

用於建立 GraphQL API 的 Ruby 程式庫。

要使用 graphql-ruby 執行 hello world 腳本

gem install graphql

然後在 hello.rb 中執行 ruby hello.rb

require 'graphql'
class QueryType < GraphQL::Schema::Object
field :hello, String
def hello
"Hello world!"
end
end
class Schema < GraphQL::Schema
query QueryType
end
puts Schema.execute('{ hello }').to_json

還有 Relay 和 Rails 的不錯繫結。

Agoo

gemagoo
星號1k
授權MIT 授權

支援 GraphQL 的高性能網路伺服器。Agoo 致力於為 GraphQL 提供一個簡單易用的 API。

require 'agoo'
class Query
def hello
'hello'
end
end
class Schema
attr_reader :query
def initialize
@query = Query.new()
end
end
Agoo::Server.init(6464, 'root', thread_count: 1, graphql: '/graphql')
Agoo::Server.start()
Agoo::GraphQL.schema(Schema.new) {
Agoo::GraphQL.load(%^type Query { hello: String }^)
}
sleep
# To run this GraphQL example type the following then go to a browser and enter
# a URL of localhost:6464/graphql?query={hello}
#
# ruby hello.rb

Rails GraphQL

最後釋出1 個月前
星星165
授權MIT 授權

一個專注於自然且類似 Ruby DSL 的 Rails 應用程式全新 GraphQL 伺服器

require 'rails-graphql'
class GraphQL::AppSchema < GraphQL::Schema
query_fields do
field(:hello).resolve { 'Hello World!' }
end
end
puts GraphQL::AppSchema.execute('{ hello }')

少即是多!請查看文件

Swift / Objective-C

伺服器

Graphiti

最後發布4 個月前
星號1k
授權MIT 授權

用於快速、安全且輕鬆建立 GraphQL 架構/類型的 Swift 函式庫。

GraphZahl

最新版本2 年前
星星143
授權MIT 授權

用於撰寫宣告式、類型安全 GraphQL API 的 Swift 函式庫,零樣板程式碼。

客戶端

Apollo iOS

最後發布1 週前
星星數4k
授權MIT 授權

一個 iOS GraphQL 用戶端,它會將結果傳回為特定於查詢的 Swift 類型,並與 Xcode 整合以並排顯示您的 Swift 原始碼和 GraphQL,以及內嵌驗證錯誤。

SwiftGraphQL

最後發布2 個月前
星號1k
授權MIT 授權

一個讓您忘記 GraphQL 的 GraphQL 用戶端。

SwiftGraphQL 是一個 Swift 程式碼產生器和輕量級 GraphQL 用戶端。它讓您可以使用 Swift 建立查詢,並保證您建立的每個查詢都是有效的。

此函式庫圍繞三個核心原則

🚀 如果你的專案編譯成功,你的查詢就會運作。🦉 盡可能在 GraphQL 中使用 Swift。🌳 你的應用程式模型應該獨立於你的架構。

以下是 SwiftGraphQL 程式碼的簡短預覽

import SwiftGraphQL
// Define a Swift model.
struct Human: Identifiable {
let id: String
let name: String
let homePlanet: String?
}
// Create a selection.
let human = Selection.Human {
Human(
id: try $0.id(),
name: try $0.name(),
homePlanet: try $0.homePlanet()
)
}
// Construct a query.
let query = Selection.Query {
try $0.humans(human.list)
}
// Perform the query.
send(query, to: "http://swift-graphql.heroku.com") { result in
if let data = try? result.get() {
print(data) // [Human]
}
}

Graphaello

最新版本2 年前
星星494
授權MIT 授權

使用 GraphQL 和 Apollo 在 SwiftUI 中撰寫宣告式、類型安全和資料驅動應用程式的工具

GraphQL iOS

星星62
授權MIT 授權

適用於 iOS 的 Objective-C GraphQL 客戶端。

GraphQLite iOS

最後發布5 個月前
星星5
授權MIT 授權

GraphQLite iOS SDK 是與 GraphQL 伺服器輕鬆運作的工具包。它還提供其他多項功能,讓 iOS 應用程式開發更輕鬆。

伺服器

absinthe

最新版本2 年前
星星數4k
授權其他

Elixir 的 GraphQL 實作。

Facebook GraphQL 的 Elixir 實作。

客戶端

common_graphql_client

最後一次發布3 年前
星星43
授權MIT 授權

支援 HTTP 和 WebSocket 的 Elixir GraphQL 客戶端

適用於 Elixir 的 GraphQL 客戶端

伺服器

Sangria

最後釋出1 個月前
星數2k
授權Apache License 2.0

支援 Relay 的 Scala GraphQL 函式庫。

一個使用 sangria 的 hello world GraphQL 架構和查詢範例

import sangria.schema._
import sangria.execution._
import sangria.macros._
val QueryType = ObjectType("Query", fields[Unit, Unit](
Field("hello", StringType, resolve = _ ⇒ "Hello world!")
))
val schema = Schema(QueryType)
val query = graphql"{ hello }"
Executor.execute(schema, query) map println

Caliban

最後釋出2 週前
星號1k
授權Apache License 2.0

Caliban 是用於在 Scala 中建置 GraphQL 伺服器和客戶端的函式庫。它提供了最少的樣板程式碼和絕佳的互通性。

一個使用 caliban 的簡單 GraphQL 架構和查詢範例

import caliban._
import caliban.schema.Schema.auto._
// schema
case class Query(hello: String)
// resolver
val resolver = RootResolver(Query("Hello world!"))
val api = graphQL(resolver)
for {
interpreter <- api.interpreter
result <- interpreter.execute("{ hello }")
} yield result

客戶端

Caliban

最後釋出2 週前
星號1k
授權Apache License 2.0

Caliban 是用於在 Scala 中建置 GraphQL 伺服器和客戶端的函式庫。它提供了客戶端程式碼產生和類型安全查詢。

一個使用 caliban 定義 GraphQL 查詢和執行它的範例

// define your query using Scala
val query: SelectionBuilder[RootQuery, List[CharacterView]] =
Query.characters {
(Character.name ~ Character.nicknames ~ Character.origin)
.mapN(CharacterView)
}
import sttp.client3._
// run the query and get the result already parsed into a case class
val result = query.toRequest(uri"http://someUrl").send(HttpClientSyncBackend()).body

Flutter

客戶端

graphql

最後發布2 個月前
星號3k
授權MIT 授權

一個在 Flutter 中實作的 GraphQL 客戶端。

Ferry

星號1k
授權MIT 授權

Ferry 是 Flutter 和 Dart 的簡單、強大的 GraphQL 客戶端。

伺服器

lacinia

星數2k
授權其他

一個 GraphQL 規範的完整實作,旨在維持與規範的外部相容性。

graphql-clj

星星282
授權Eclipse Public License 1.0

一個提供 GraphQL 實作的 Clojure 函式庫。

使用 graphql-clj 執行 hello world GraphQL 查詢的程式碼

(def schema "type QueryRoot {
hello: String
}")
(defn resolver-fn [type-name field-name]
(get-in {"QueryRoot" {"hello" (fn [context parent & rest]
"Hello world!")}}
[type-name field-name]))
(require '[graphql-clj.executor :as executor])
(executor/execute nil schema resolver-fn "{ hello }")

alumbra

最後釋出6 年前
星星148
授權MIT 授權

一個可重複使用的 GraphQL 元件組,適用於符合 alumbra.spec 中所提供資料結構的 Clojure。

(require '[alumbra.core :as alumbra]
'[claro.data :as data])
(def schema
"type Person { name: String!, friends: [Person!]! }
type QueryRoot { person(id: ID!): Person, me: Person! }
schema { query: QueryRoot }")
(defrecord Person [id]
data/Resolvable
(resolve! [_ _]
{:name (str "Person #" id)
:friends (map ->Person (range (inc id) (+ id 3)))}))
(def QueryRoot
{:person (map->Person {})
:me (map->Person {:id 0})})
(def app
(alumbra/handler
{:schema schema
:query QueryRoot}))
(defonce my-graphql-server
(aleph.http/start-server #'app {:port 3000}))
$ curl -XPOST "http://0:3000" -H'Content-Type: application/json' -d'{
"query": "{ me { name, friends { name } } }"
}'
{"data":{"me":{"name":"Person #0","friends":[{"name":"Person #1"},{"name":"Person #2"}]}}}

客戶端

重繪圖形

最後發布1 年前
星號455
授權未知

使用 Clojurescript 執行的 GraphQL 客戶端,支援網路插座。

伺服器

Morpheus GraphQL

最後版本10 個月前
星號400
授權MIT 授權

用於建置 GraphQL API 的 Haskell 函式庫。

使用 morpheus-graphql 的 Hello World 範例

# schema.gql
"""
A supernatural being considered divine and sacred
"""
type Deity {
name: String!
power: String @deprecated(reason: "no more supported")
}
type Query {
deity(name: String! = "Morpheus"): Deity!
}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module API (api) where
import Data.ByteString.Lazy.Char8 (ByteString)
import Data.Morpheus (interpreter)
import Data.Morpheus.Document (importGQLDocument)
import Data.Morpheus.Types (RootResolver (..), Undefined (..))
import Data.Text (Text)
importGQLDocument "schema.gql"
rootResolver :: RootResolver IO () Query Undefined Undefined
rootResolver =
RootResolver
{ queryResolver = Query {deity},
mutationResolver = Undefined,
subscriptionResolver = Undefined
}
where
deity DeityArgs {name} =
pure
Deity
{ name = pure name,
power = pure (Just "Shapeshifting")
}
api :: ByteString -> IO ByteString
api = interpreter rootResolver

請參閱 morpheus-graphql-examples 以取得更精密的 API。

Mu-Haskell 搭配 Mu-GraphQL

最後一次發布3 年前
星號325
授權Apache License 2.0

用於建置微服務 (gRPC、HTTP) 和 GraphQL API 的 Haskell 函式庫。

範例實作:GraphQL 伺服器,搭配自動產生的類型層級架構表示

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
-- imports omitted for brevity...
graphql "Library" "library.graphql" -- all the magic happens here! 🪄🎩
-- ... a bit more code...
libraryServer :: SqlBackend -> ServerT ObjectMapping i Library ServerErrorIO _
libraryServer conn =
resolver
( object @"Book"
( field @"id" bookId,
field @"title" bookTitle,
field @"author" bookAuthor,
field @"imageUrl" bookImage
),
object @"Author"
( field @"id" authorId,
field @"name" authorName,
field @"books" authorBooks
),
object @"Query"
( method @"authors" allAuthors,
method @"books" allBooks
),
object @"Mutation"
( method @"newAuthor" newAuthor,
method @"newBook" newBook
),
object @"Subscription"
(method @"allBooks" allBooksConduit)
)
where
bookId :: Entity Book -> ServerErrorIO Integer
bookId (Entity (BookKey k) _) = pure $ toInteger k
-- ... more resolvers...

請參閱 我們的文件 以取得有關如何建置您自己的 GraphQL 伺服器,以及 函式庫範例 以取得更完整的範例,其中包括使用 Elm編寫的客戶端!

graphql-w-persistent

星號10
授權未知

完整的函式庫工具組,用於摘要 SQL 的關聯式資料庫架構、使用 GraphQL 進行查詢,並傳回 GraphQL 結果

一次性設定:建置架構、部署為微服務或在伺服器內部,使用 GraphQL查詢 SQL 資料庫!

客戶端

morpheus-graphql-client

最後版本10 個月前
星號400
授權MIT 授權

Haksell 中的強類型 GraphQL 客戶端實作。

C / C++

工具

libgraphqlparser

最後釋出6 年前
星號1k
授權MIT 授權

具備 C 和 C++ API 的 C++ GraphQL 查詢語言解析器。

OCaml / Reason

伺服器

ocaml-graphql-server

最後發布1 年前
星號1k
授權MIT 授權

OCaml 和 Reason 的 GraphQL 伺服器函式庫

Erlang

伺服器

graphql-erlang

最後發布5 年前
星星313
授權其他

Erlang 中的 GraphQL 實作。

Ballerina

伺服器

ballerina-graphql

最新版本4 週前
星星144
授權Apache License 2.0

用於撰寫 GraphQL 服務的 Ballerina 標準函式庫套件。

執行 ballerina-graphql hello world 伺服器

  • 下載並安裝 Ballerina 語言
  • 然後執行 bal run graphql_service.bal 執行服務,並在 graphql_service.bal 檔案中使用此程式碼
import ballerina/graphql;
service /graphql on new graphql:Listener(9090) {
resource function get hello() returns string {
return "Hello, world!";
}
}

功能#

  • 使用 Ballerina servicelistener 模型建置,它們是 Ballerina 中的一等公民
  • 支援透過 websocket 進行訂閱(不需要其他函式庫)
  • 支援檔案上傳
  • 內建 GraphiQL 客戶端

客戶端

ballerina-graphql

最新版本4 週前
星星144
授權Apache License 2.0

用於使用 GraphQL 服務的 Ballerina 標準函式庫套件。

執行 ballerina-graphql 客戶端

  • 下載並安裝 Ballerina 語言
  • 然後執行 bal run graphql_client.bal 執行服務,並在 graphql_client.bal 檔案中使用此程式碼
import ballerina/graphql;
import ballerina/io;
type Response record {
record { string hello; } data;
};
public function main() returns error? {
graphql:Client helloClient = check new ("localhost:9090/graphql");
string document = "{ hello }";
Response response = check helloClient->execute(document);
io:println(response.data.hello);
}

功能#

  • 使用 Ballerina 型別推論進行依賴型別回應擷取
  • 自訂客戶端產生支援

Julia

客戶端

Diana.jl

最後發布1 年前
星星112
授權MIT 授權

Julia GraphQL 伺服器實作。

GraphQLClient.jl

最後發布1 年前
星星46
授權其他

Julia GraphQL 程式庫,可與 GraphQL 伺服器無縫整合

  • 查詢變異訂閱,而不用手動撰寫查詢字串(除非您想這樣做!)
  • 直接將回應反序列化為 Julia 類型
  • 從 GraphQL 物件建構 Julia 類型
  • 使用內省協助查詢

快速入門#

使用 Julia 的套件管理員安裝

using Pkg; Pkg.add("GraphQLClient")
using GraphQLClient

連線到伺服器

client = Client("https://countries.trevorblades.com")

從 GraphQL 物件建構 Julia 類型

Country = GraphQLClient.introspect_object(client, "Country")

並查詢伺服器,將回應反序列化為這個新類型

response = query(client, "countries", Vector{Country}, output_fields="name")

或者手動撰寫查詢字串

query_string = """
{
countries{
name
}
}"""
response = GraphQLClient.execute(client, query_string)

R

伺服器

ghql

最後一次發布4 年前
星星141
授權其他

通用的 GraphQL R 程式庫

Groovy

伺服器

gorm-graphql

最後發布3 個月前
星星80
授權Apache License 2.0

GORM 的自動 GraphQL 架構產生器

核心函式庫 - GORM GraphQL 函式庫提供根據 GORM 實體產生 GraphQL 架構的功能。除了將網域類別對應到 GraphQL 架構外,核心函式庫也提供「資料擷取器」的預設實作,以透過執行架構來查詢、更新和刪除資料。

Grails 外掛 - 除了核心函式庫外,GORM GraphQL Grails 外掛

  • 根據其準則,提供一個控制器來接收和回應 GraphQL 請求,透過 HTTP。

  • 在啟動時產生架構,並使用 Spring bean 組態,以利於擴充。

  • 包含一個 GraphiQL 瀏覽器,在開發中預設啟用。瀏覽器可透過 /graphql/browser 存取。

  • 覆寫預設資料繫結器,以使用 Grails 提供的資料繫結。

  • 提供一個 特質,以簡化 GraphQL 端點的整合測試

請參閱 文件 以取得更多資訊。

GQL

最後發布1 年前
星星47
授權Apache License 2.0

GQL 是 GraphQL 的 Groove 函式庫

Perl

伺服器

graphql-perl

星星70
授權未知

GraphQL 參考實作的 Perl 移植

Elm

客戶端

函式庫和命令列程式碼產生器,用於為 GraphQL 端點建立類型安全的 Elm 程式碼。

D

伺服器

D 程式語言的 GraphQL 實作。

閘道器/超級圖

WunderGraph

最後發布1 週前
星數2k
授權Apache License 2.0

WunderGraph 是開源 GraphQL 閘道器,能夠組合 Apollo Federation、GraphQL、REST API、資料庫、Kafka 等。

WunderGraph 將所有 API 組合到單一的統一 GraphQL API 中,並允許您將圖表公開為 安全且類型安全的 JSON-RPC API

要開始使用 WunderGraph,您可以使用 create-wundergraph-app 來引導新專案

npx create-wundergraph-app my-project -E nextjs-swr

在客戶端,WunderGraph 的 JSON-RPC API 與 Next.js、SWR 和 React Query 等框架整合得非常好,而在後端,我們能夠利用「伺服器端專用 GraphQL」的效能。直接在查詢層處理驗證、授權、驗證、聯結等。

mutation (
$name: String! @fromClaim(name: NAME)
$email: String! @fromClaim(name: EMAIL)
$message: String! @jsonSchema(pattern: "^[a-zA-Z 0-9]+$")
) {
createOnepost(
data: {
message: $message
user: {
connectOrCreate: {
where: { email: $email }
create: { email: $email, name: $name }
}
}
}
) {
id
message
user {
id
name
}
}
}

上述查詢需要使用者通過驗證,從 JWT 令牌中注入使用者的姓名和電子郵件,並根據 JSON Schema 驗證訊息。

以下是如何使用 WunderGraph 獨特的 聯結功能,將兩個不同 API 的資料組合到單一 GraphQL 回應中的另一個範例。

query (
$continent: String!
# the @internal directive removes the $capital variable from the public API
# this means, the user can't set it manually
# this variable is our JOIN key
$capital: String! @internal
) {
countries_countries(filter: { continent: { eq: $continent } }) {
code
name
# using the @export directive, we can export the value of the field `capital` into the JOIN key ($capital)
capital @export(as: "capital")
# the _join field returns the type Query!
# it exists on every object type so you can everywhere in your Query documents
_join {
# once we're inside the _join field, we can use the $capital variable to join the weather API
weather_getCityByName(name: $capital) {
weather {
temperature {
max
}
summary {
title
description
}
}
}
}
}
}

完整的 範例可以在 GitHub 上找到

一般

quicktype

星星數11k
授權Apache License 2.0

在 TypeScript、Swift、golang、C#、C++ 等語言中產生 GraphQL 查詢的類型。

GraphQL 程式碼產生器

最後發布3 週前
星星數11k
授權MIT 授權

GraphQL 程式碼產生器,彈性支援自訂外掛程式和範本,例如 Typescript(前端和後端)、React Hooks、解析程式簽章等。

Schemathesis

最後釋出2 週前
星數2k
授權MIT 授權

一個現代的 API 測試工具,適用於使用 Open API 和 GraphQL 規範所建置的網路應用程式。

透過 Docker 在 GraphQL 端點上執行 Schemathesis

docker run schemathesis/schemathesis \
run https://your.app.com/graphql

Schemathesis 會產生與 GraphQL 架構相符的查詢,並自動捕捉伺服器當機。產生的查詢具有任意深度,且可能包含輸入架構中定義的任何 GraphQL 類型子集。它們會揭露程式碼中不太可能以其他方式找到的邊緣狀況。

請注意,你可以使用任何程式語言撰寫應用程式;此工具會透過 HTTP 與其通訊。

例如,針對 https://bahnql.herokuapp.com/graphql 執行上述指令會發現執行 { search(searchTerm: "") { stations { name } } } 查詢會導致伺服器錯誤

{
"errors": [
{
"message": "Cannot read property 'city' of undefined",
"locations": [
{
"line": 1,
"column": 28
}
],
"path": [
"search",
"stations"
]
}
],
"data": null
}

Microcks

星號1k
授權Apache License 2.0

用於 API 模擬和測試的開源 Kubernetes 原生工具

Microcks 是個平台,可以將你的 API 和微服務資產(GraphQL 架構OpenAPI 規範AsyncAPI 規範gRPC protobufPostman 彙整SoapUI 專案_)在數秒內轉換成即時模擬。

它也會重複使用這些資產,針對你的 API 實作執行相符性和非回歸測試。我們透過一個簡單的 CLI 提供與 JenkinsGitHub ActionsTekton 和許多其他工具的整合。

gqt

星號455
授權MIT 授權

在終端機中建置和執行 GraphQL 查詢。

針對 GraphQL 端點執行 gqt。在直覺式 TUI 中建立查詢並執行。伺服器的回應會寫入標準輸出。

gqt -e https://your.app.com/graphql

GraphQL Armor

最後發布2 個月前
星星453
授權MIT 授權

Apollo GraphQL 和 Yoga / Envelop 伺服器遺失的 GraphQL 安全層。

服務#

Webiny 讓您能夠快速在 AWS Lambda 和 DynamoDB 上建立 GraphQL API,並內建架構。Webiny 也包含現成的無頭 GraphQL CMS,提供免寫程式碼的體驗。

Typetta 是一個以 TypeScript 編寫的開源 ORM,旨在讓所有主要的 SQL 資料庫(MySQL、PostgreSQL、Microsoft SQL Server、SQLLite3、CockroachDB、MariaDB、Oracle 和 Amazon Redshift)以及 NoSQL 資料庫 MongoDB 都能以類型化的方式無縫存取資料。

Tyk 是一個輕量級的開源 API 管理閘道,它以使用 Golang 編寫的 GraphQL 引擎為核心,建立了 GraphQL 的完整 API 生命週期管理。Tyk 支援透過 通用資料圖 (UDG) 將多個 GraphQL 和/或 REST API 的架構拼接起來,以及 GraphQL 聯盟GraphQL 訂閱

SaaS(軟體即服務)內容管理系統,可讓你使用強大的編輯工具建立你的內容,並透過 GraphQL 或 REST API 從任何地方存取。

根據你的資料來源(REST 和資料庫)、第三方 API 或任何組合,建立無伺服器 GraphQL API。你無需自行撰寫 GraphQL 伺服器,而是可以透過撰寫 GraphQL 架構,以宣告方式定義所有內容。如需更多資訊,請前往 https://www.stepzen.com/

新一代 Node.js 和 TypeScript ORM,內建資料載入器,可用於建置 GraphQL 後端。如需更多資訊,請前往 https://prisma.dev.org.tw/graphql

強大的多協定 API 應用程式介面客戶端,具備 API 腳本、自動化、協作工作空間等功能,並全面支援測試和開發 GraphQL API。

GraphQL 分析和監控服務,用於找出功能和效能問題。

無頭 CMS(內容管理系統),結合強大的內容個人化和排程功能,以及現代化的內容編輯體驗和極速的 GraphQL/REST 內容傳遞 API。

Insomnia 是一個開源、跨平台的 API 客户端,適用於 GraphQL、REST 和 gRPC。Insomnia 結合了易於使用的介面與進階功能,例如驗證輔助工具、程式碼產生和環境變數。

Hygraph 是聯合內容平台,讓您的堆疊具有真正的可組合性。透過獨特的內容聯合方式整合所有服務,並使用單一強大的 GraphQL API 從任何地方分發內容到任何地方。

Hasura 連線到您的資料庫和微服務,並立即為您提供可立即投入生產的 GraphQL API。

快速且免費的安全掃描,可在 GraphQL 端點上執行十幾項測試。無需登入。

graphapi® 是一個安全的低程式碼 GraphQL 即服務平台。根據輸入資料模型,它會自動產生 GraphQL 架構、所有解析器和資料庫堆疊。此外,它還提供一個使用者介面,讓團隊可以管理他們的資料。如需更多資訊,請前往 https://graphapi.com

輕鬆製作 GraphQL 後端。使用架構優先的方法,以宣告方式建立您的後端。透過利用強大的指令和純量,加速開發並減少樣板程式碼。

透過匯入 gql 架構,建立即時的 GraphQL 後端。資料庫會為您建立關係和索引,因此您可以在幾秒鐘內進行查詢,而無需撰寫任何資料庫程式碼。無伺服器定價,免費開始使用。

即時 GraphQL 安全性和相容性。確保您的 GraphQL 端點已準備好投入生產。在開發期間。無需設定。支援所有語言和架構。免費開始使用。

一個 Java 函式庫,可以將 JPA 標註資料模型公開為任何關聯式資料庫上的 GraphQL 服務。

Dgraph

Dgraph 是一個具有圖形後端的原生 GraphQL 資料庫。這表示 Dgraph 不是建立在現有資料庫(例如 Postgres)之上的介面,而是實際上從頭開始為 GraphQL 設計。它針對速度和效能進行最佳化,仰賴多項電腦科學突破技術以獲得最佳結果。Dgraph Cloud 是一個完全受控的 GraphQL 後端服務,讓您無需擔心基礎架構即可更快速地進行反覆運算。

如果在 Linux 上本地執行(而非在 Dgraph Cloud 上),請執行安裝步驟

docker pull dgraph/standalone
mkdir -p ~/dgraph
docker run -it -p 5080:5080 -p 6080:6080 -p 8080:8080 \
-p 9080:9080 -p 8000:8000 -v ~/dgraph:/dgraph --name dgraph \
dgraph/standalone:master

設定您的 GraphQL 架構

touch schema.graphql
nano schema.graphql
type Product {
id: ID!
name: String! @id
reviews: [Review] @hasInverse(field: about)
}
type Customer {
username: String! @id
reviews: [Review] @hasInverse(field: by)
}
type Review {
id: ID!
about: Product!
by: Customer!
comment: String @search(by: [fulltext])
rating: Int @search
}
curl -X POST localhost:8080/admin/schema --data-binary '@schema.graphql'

啟動您最愛、指向 http://localhost:8080/graphql 的 GraphQL Client,並執行突變和查詢

mutation {
addProduct(input: [{ name: "Dgraph" }, { name: "Dgraph Cloud" }]) {
product {
id
name
}
}
addCustomer(input: [{ username: "TonyStark" }]) {
customer {
username
}
}
}
mutation {
addReview(
input: [
{
by: { username: "TonyStark" }
about: { name: "Dgraph" }
comment: "Fantastic, easy to install, worked great. Best GraphQL server available"
rating: 10
}
]
) {
review {
id
comment
rating
by {
username
}
about {
id
name
}
}
}
}
query {
queryReview(filter: { comment: { alloftext: "server easy install" }, rating: { gt: 5 } }) {
comment
by {
username
reviews(order: { desc: rating }, first: 10) {
about {
name
reviews(order: { asc: rating, first: 5 }) {
by { username }
comment
rating
}
}
rating
}
}
about {
name
}
}
}

ChilliCream 提供的一個功能豐富的 GraphQL IDE,讓您可以探索、管理和測試您的 GraphQL API。在此處查看 此處

完全受控的 GraphQL 後端,基於開源的 Parse Platform。透過 GraphQL API 儲存和查詢關聯式資料、執行雲端函式等等。免費開始使用。

完全受控的 GraphQL 服務,具有即時訂閱、離線程式設計和同步,以及企業安全功能和細緻的授權控制。

一個雲端服務,可協助您建立、驗證、監控和保護您組織的資料圖形。

Apache APISIX 是一個動態、即時、高性能的 API 閘道,提供豐富的流量管理功能,例如負載平衡、動態上游、金絲雀發布、可觀察性等。作為一個雲原生 API 閘道,Apache APISIX 在其設計之初就已經可以支援 GraphQL 語法。有效地比對請求中攜帶的 GraphQL 陳述式,可以過濾異常流量,進一步確保安全性。更多資訊,請參閱 如何將 GraphQL 與 API 閘道 Apache APISIX 整合

一個 GraphQL API,可以查詢和變更 Salesforce、HubSpot、Microsoft Dynamics、Pipedrive 等 API 的資料。

Postman 的替代方案,支援直接編輯 GraphQL 查詢並自動載入您的 GraphQL 架構。

想要改善此頁面嗎?請參閱 此處的說明文件