From 342afd5a11b0fa4c1dc5f177bf2bc49033462f8f Mon Sep 17 00:00:00 2001 From: Jeremy Prevost Date: Thu, 12 Nov 2026 09:14:23 -0500 Subject: [PATCH] Handle missing identifiers in deprecated fields Return nil instead of raising an error when a record has no identifiers, and add a regression test. This branch should return record with null isbns, production will return error for this query: ``` { recordId(id: "alma:9935045653306761") { title isbns } } ``` https://mitlibraries.atlassian.net/browse/TIMX-746 Sentry: TIMDEX-6Q --- app/graphql/types/record_type.rb | 2 +- test/graphql/types/record_type_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/graphql/types/record_type.rb b/app/graphql/types/record_type.rb index 1d7a5e09..0f0b27df 100644 --- a/app/graphql/types/record_type.rb +++ b/app/graphql/types/record_type.rb @@ -249,7 +249,7 @@ def dois end def deprecated_identifiers(field) - @object['identifiers'].map { |id| id['value'] if id['kind'] == field }.compact + @object['identifiers']&.map { |id| id['value'] if id['kind'] == field }&.compact end end end diff --git a/test/graphql/types/record_type_test.rb b/test/graphql/types/record_type_test.rb index 0c5574be..f533e306 100644 --- a/test/graphql/types/record_type_test.rb +++ b/test/graphql/types/record_type_test.rb @@ -30,4 +30,10 @@ class RecordTypeTest < ActiveSupport::TestCase result = record_type.file_formats assert_equal %w[PDF EPUB], result, 'file_formats should return unique values' end + + test 'deprecated identifiers return nil when identifiers key is missing' do + record_type = Types::RecordType.send(:new, { 'title' => 'Test Record' }, {}) + + assert_nil record_type.isbns + end end