object_type_definition.ex (2726B)
1 defmodule Absinthe.Blueprint.Schema.ObjectTypeDefinition do 2 @moduledoc false 3 4 alias Absinthe.{Blueprint, Type} 5 6 @enforce_keys [:name] 7 defstruct [ 8 :name, 9 :identifier, 10 :module, 11 description: nil, 12 interfaces: [], 13 interface_blueprints: [], 14 fields: [], 15 directives: [], 16 is_type_of: nil, 17 source_location: nil, 18 # Added by phases 19 flags: %{}, 20 imports: [], 21 errors: [], 22 __reference__: nil, 23 __private__: [] 24 ] 25 26 @type t :: %__MODULE__{ 27 name: String.t(), 28 identifier: atom, 29 description: nil | String.t(), 30 fields: [Blueprint.Schema.FieldDefinition.t()], 31 interfaces: [String.t()], 32 interface_blueprints: [Blueprint.Draft.t()], 33 directives: [Blueprint.Directive.t()], 34 source_location: nil | Blueprint.SourceLocation.t(), 35 # Added by phases 36 flags: Blueprint.flags_t(), 37 errors: [Absinthe.Phase.Error.t()], 38 __private__: Keyword.t() 39 } 40 41 @doc false 42 def functions(), do: [:is_type_of] 43 44 def build(type_def, schema) do 45 %Type.Object{ 46 identifier: type_def.identifier, 47 name: type_def.name, 48 description: type_def.description, 49 fields: build_fields(type_def, schema), 50 interfaces: type_def.interfaces, 51 definition: type_def.module, 52 is_type_of: type_def.is_type_of, 53 __private__: type_def.__private__ 54 } 55 end 56 57 def build_fields(type_def, schema) do 58 for field_def <- type_def.fields, into: %{} do 59 field = %Type.Field{ 60 identifier: field_def.identifier, 61 middleware: field_def.middleware, 62 deprecation: field_def.deprecation, 63 description: field_def.description, 64 complexity: field_def.complexity, 65 config: field_def.complexity, 66 triggers: field_def.triggers, 67 name: field_def.name, 68 type: Blueprint.TypeReference.to_type(field_def.type, schema), 69 args: build_args(field_def, schema), 70 definition: field_def.module, 71 __reference__: field_def.__reference__, 72 __private__: field_def.__private__ 73 } 74 75 {field.identifier, field} 76 end 77 end 78 79 def build_args(field_def, schema) do 80 Map.new(field_def.arguments, fn arg_def -> 81 arg = %Type.Argument{ 82 identifier: arg_def.identifier, 83 name: arg_def.name, 84 description: arg_def.description, 85 type: Blueprint.TypeReference.to_type(arg_def.type, schema), 86 default_value: arg_def.default_value, 87 deprecation: arg_def.deprecation 88 } 89 90 {arg_def.identifier, arg} 91 end) 92 end 93 94 defimpl Inspect do 95 defdelegate inspect(term, options), 96 to: Absinthe.Schema.Notation.SDL.Render 97 end 98 end