Class: Capsium::Reactor::GraphqlApi
- Inherits:
-
Object
- Object
- Capsium::Reactor::GraphqlApi
- Includes:
- Responses
- Defined in:
- lib/capsium/reactor/graphql_api.rb,
sig/capsium/reactor/graphql_api.rbs
Overview
GraphQL over a mount's datasets (POST and GET
Constant Summary collapse
- PATH =
"/graphql"
Class Method Summary collapse
Instance Method Summary collapse
-
#collection(dataset, id: nil) ⇒ Array[untyped]
Query/mutation resolvers called from the derived schema.
- #create_item(dataset, item:) ⇒ Object
- #handle(request, response) ⇒ Object
-
#initialize(mount) ⇒ GraphqlApi
constructor
A new instance of GraphqlApi.
- #remove_item(dataset, id:) ⇒ Boolean
- #update_item(dataset, id:, item:) ⇒ Object
Methods included from Responses
#respond_error, #respond_forbidden, #respond_json, #respond_method_not_allowed, #respond_not_found, #respond_not_implemented, #respond_text
Constructor Details
#initialize(mount) ⇒ GraphqlApi
Returns a new instance of GraphqlApi.
23 24 25 26 |
# File 'lib/capsium/reactor/graphql_api.rb', line 23 def initialize(mount) @mount = mount @schema = GraphqlSchema.new(mount, self).build end |
Class Method Details
.path?(inner_path) ⇒ Boolean
19 20 21 |
# File 'lib/capsium/reactor/graphql_api.rb', line 19 def self.path?(inner_path) inner_path == PATH end |
Instance Method Details
#collection(dataset, id: nil) ⇒ Array[untyped]
Query/mutation resolvers called from the derived schema.
38 39 40 41 42 43 44 |
# File 'lib/capsium/reactor/graphql_api.rb', line 38 def collection(dataset, id: nil) return @mount..items(dataset) if id.nil? [@mount..item(dataset, id)] rescue Overlay::Error => e raise execution_error(e) end |
#create_item(dataset, item:) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/capsium/reactor/graphql_api.rb', line 46 def create_item(dataset, item:) ensure_writable! @mount..append_item(dataset, item) item rescue Overlay::Error => e raise execution_error(e) end |
#handle(request, response) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/capsium/reactor/graphql_api.rb', line 28 def handle(request, response) case request.request_method when "POST" then handle_post(request, response) when "GET" then handle_get(request, response) else respond_method_not_allowed(response) end end |