実装の比較(リクエスト)
13
REST
https://some.where/customers
GET
GraphQL
https://some.where/graphql
POST
query {
customers {
fullname
email
}
}
Slide 14
Slide 14 text
実装の比較(インターフェース)
14
REST
app/controllers/customers_controll
er.rb
class CustomersController
def index
@customers = Customer.some_scope
end
end
GraphQL
app/graphql/types/query_type.rb
module Types
class QueryType < Types::BaseObject
field :customers, [CustomerType], null:
true
def customers
@customers = Customer.some_scope
end
end
end
Slide 15
Slide 15 text
実装の比較(詳細定義)
15
REST
app/views/customers/index.json.jb
uilder
json.customers @customers do | c |
json.name c.name
json.email c.email
...
end
↑ 該当のリクエスト専用の定義のため再利用不
可
GraphQL
app/graphql/types/customer_type.r
b
module Types
class CustomerType < Types::BaseObject
field :name, String
field :email, String
end
end
↑ 該当のリクエスト専用の定義ではないので再
利用可能(ActiveRecordの定義同様)