ruby里面使用graphql
文章目录
安装graphql模块
gem install graphql
使用ruby hello.rb运行hello.rb中的代码:
require 'graphql'
module Schemas
module Types
class User < GraphQL::Types::Relay::BaseObject
field :id, String, null: true
field :title, String, null: true
end
end
end
class QueryType < GraphQL::Schema::Object
graphql_name 'Query'
field :user,Schemas::Types::User,null:true do
argument :id, String, required: true
argument :title, String, required: false
end
def user(id)
puts id
{
title: 121,
id: 1231
}
end
end
class Schema < GraphQL::Schema
query QueryType
end
puts Schema.execute('{ user(id: "123", title: "aa") {title} }').to_json
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论