Browse Source

Maintenance: Remove Base64 transcoding for GraphQL IDs.

Martin Gruner 2 years ago
parent
commit
26e03c072b

+ 1 - 1
app/graphql/gql/zammad_schema.rb

@@ -35,7 +35,7 @@ class Gql::ZammadSchema < GraphQL::Schema
 
   # Return a string UUID for `object`
   def self.id_from_object(object, _type_definition = nil, _query_ctx = nil)
-    object.to_gid_param
+    object.to_global_id.to_s
   end
 
   # Given a string UUID, find the object.

+ 2 - 2
spec/graphql/gql/mutations/online_notification/mark_all_as_seen_spec.rb

@@ -51,8 +51,8 @@ RSpec.describe Gql::Mutations::OnlineNotification::MarkAllAsSeen, authenticated_
     it 'returns touched notifications' do
       expect(gql.result.data['onlineNotifications'])
         .to contain_exactly(
-          include('id' => notification_a.to_gid_param),
-          include('id' => notification_b.to_gid_param)
+          include('id' => gql.id(notification_a)),
+          include('id' => gql.id(notification_b))
         )
     end
   end

+ 1 - 1
spec/graphql/gql/queries/online_notifications_spec.rb

@@ -33,7 +33,7 @@ RSpec.describe Gql::Queries::OnlineNotifications, type: :graphql do
     it 'contains a notification', authenticated_as: :user do
       returned_ids = gql.result.nodes.map { |elem| elem['id'] }
 
-      expect(returned_ids).to contain_exactly(notification.to_gid_param)
+      expect(returned_ids).to contain_exactly(gql.id(notification))
     end
   end
 end

+ 14 - 0
spec/graphql/gql/zammad_schema_global_id_spec.rb

@@ -0,0 +1,14 @@
+# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
+
+require 'rails_helper'
+
+RSpec.describe Gql::ZammadSchema, type: :graphql do
+
+  it 'generates GraphQL::ID values' do
+    expect(described_class.id_from_object(Ticket.first)).to eq('gid://zammad/Ticket/1')
+  end
+
+  it 'resolves GraphQL::ID values' do
+    expect(described_class.object_from_id('gid://zammad/Ticket/1')).to eq(Ticket.first)
+  end
+end