lib/graphiti_gql/schema.rb in graphiti_gql-0.2.33 vs lib/graphiti_gql/schema.rb in graphiti_gql-0.2.34
- old
+ new
@@ -100,11 +100,27 @@
def initialize(resources)
@resources = resources
end
+ def self.resource_types!
+ resources = Graphiti.resources.reject(&:abstract_class?)
+ resources.each { |resource| ResourceType.new(resource).build }
+ # add relationships
+ registry.resource_types.each do |registered|
+ resource, type = registered[:resource], registered[:type]
+ ResourceType.add_relationships(resource, type)
+ end
+ # add_value_objects
+ registry.resource_types(value_objects: false).each do |registered|
+ resource, type = registered[:resource], registered[:type]
+ ResourceType.add_value_objects(resource, type)
+ end
+ end
+
def generate
- klass = Class.new(::GraphQL::Schema)
+ klass = Class.new(::GraphitiGql.config.base_schema || ::GraphQL::Schema)
+ # TODO inherit from klass.query if exists
klass.query(Query.new(@resources).build)
klass.use(GraphQL::Batch)
klass.connections.add(ResponseShim, Connection)
klass.connections.add(Array, ToManyConnection)
klass.orphan_types [GraphQL::Types::JSON]