Class: Capsium::Reactor::GraphqlSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/capsium/reactor/graphql_schema.rb,
sig/capsium/reactor/graphql_schema.rbs

Overview

Builds the GraphQL schema for a mounted package: per dataset a query field "" (list, optional "id:") plus create/update/delete mutations. Item types are inferred from the dataset's JSON schema when present.

Defined Under Namespace

Classes: JsonScalar

Instance Method Summary collapse

Constructor Details

#initialize(mount, api) ⇒ GraphqlSchema

Returns a new instance of GraphqlSchema.

Parameters:



26
27
28
29
# File 'lib/capsium/reactor/graphql_schema.rb', line 26

def initialize(mount, api)
  @mount = mount
  @api = api
end

Instance Method Details

#buildsingleton(GraphQL::Schema)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/capsium/reactor/graphql_schema.rb', line 31

def build
  api = @api
  query_type = Class.new(GraphQL::Schema::Object) { graphql_name("Query") }
  mutation_type = Class.new(GraphQL::Schema::Object) { graphql_name("Mutation") }
  @mount.package.storage.datasets.each do |dataset|
    next if dataset.config.sqlite?

    add_dataset_fields(query_type, mutation_type, dataset, api)
  end
  Class.new(GraphQL::Schema) do
    query(query_type)
    mutation(mutation_type)
  end
end