Module: Dry::GraphQL::ROM
- Defined in:
- lib/dry/graphql/rom.rb
Overview
Adds graphql_type to a rom relation
require ‘dry/graphql/rom’
class Users < ROM::Relation
extend Dry::GraphQL::ROM
end
Instance Method Summary collapse
Instance Method Details
#graphql_type(opts = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dry/graphql/rom.rb', line 15 def graphql_type(opts = {}) return @graphql_type if @graphql_type base_schema = schema.to_output_hash schema_hash = base_schema.each_with_object({}) do |type, memo| memo[type.name] = type.type end type_name = Dry::Core::Inflector.singularize(name) graphql_name = type_name.to_s.gsub('::', '__') graphql_schema = SchemaBuilder.build_graphql_schema_class(graphql_name) graphql_schema.graphql_name(graphql_name) @graphql_type ||= Dry::GraphQL.from(schema_hash, name: type_name, schema: graphql_schema, **opts) end |