知海

Ruby:graphql-ruby(服务端)

graphql-github-io-zh-Hans生态项目与库

Ruby:graphql-ruby(服务端)

描述: 用于构建 GraphQL API 的 Ruby 库。

链接: GitHub · Gem: graphql

快速开始

使用 graphql-ruby 运行 Hello World 脚本:

bash 复制代码
gem install graphql

然后在 hello.rb 中写入以下代码,并运行 ruby hello.rb

ruby 复制代码
require 'graphql'

class QueryType < GraphQL::Schema::Object
  graphql_name 'Query'
  field :hello do
    type types.String
    resolve -> (obj, args, ctx) { 'Hello world!' }
  end
end

class Schema < GraphQL::Schema
  query QueryType
end

puts Schema.execute('{ hello }').to_json

此外还提供了适用于 Relay 和 Rails 的优秀绑定。

帮助我们改进文档

发现翻译问题或内容错误?请告诉我们。