diff --git a/lib/graphiti/util/serializer_attributes.rb b/lib/graphiti/util/serializer_attributes.rb index 7e895815..8994f529 100644 --- a/lib/graphiti/util/serializer_attributes.rb +++ b/lib/graphiti/util/serializer_attributes.rb @@ -13,7 +13,7 @@ def apply return unless readable? if @name == :id - @serializer.id(&@attr[:proc]) if @attr[:proc] + @serializer.id(&proc) elsif @attr[:proc] @serializer.send(_method, @name, serializer_options, &proc) else diff --git a/spec/serialization_spec.rb b/spec/serialization_spec.rb index 6f3c5410..d1f1a3cc 100644 --- a/spec/serialization_spec.rb +++ b/spec/serialization_spec.rb @@ -45,6 +45,33 @@ def self.name expect(json['data'][0]['attributes']).to eq('first_name' => 'John') end + context 'when id is custom type' do + before do + type = Dry::Types::Definition.new(String).constructor do |input| + 'custom!' + end + Graphiti::Types[:custom] = { + params: type, + canonical_name: :string, + read: type, + write: type, + kind: 'scalar', + description: 'test' + } + resource.attribute :id, :custom + end + + after do + Graphiti::Types.map.delete(:custom) + end + + it 'goes through type coercion' do + PORO::Employee.create + render + expect(json['data'][0]['id']).to eq('custom!') + end + end + describe 'helper functions' do let(:app_serializer) do Class.new(Graphiti::Serializer) do