From 99e22a8cbe2113bc47742975a27fa57944d7d855 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Thu, 2 Nov 2023 10:36:03 +0000 Subject: [PATCH] log(graphql): log deprecated order argument usage --- app/controllers/api/v2/base_controller.rb | 1 + app/graphql/connections/cursor_connection.rb | 9 ++++++++- .../api/v2/graphql_controller_stored_queries_spec.rb | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v2/base_controller.rb b/app/controllers/api/v2/base_controller.rb index 29ed95a57..aafcc0aa3 100644 --- a/app/controllers/api/v2/base_controller.rb +++ b/app/controllers/api/v2/base_controller.rb @@ -40,6 +40,7 @@ class API::V2::BaseController < ApplicationController if @api_token.present? @api_token.touch(:last_v2_authenticated_at) @current_user = @api_token.administrateur.user + Current.user = @current_user end end end diff --git a/app/graphql/connections/cursor_connection.rb b/app/graphql/connections/cursor_connection.rb index fa6df5e9d..913ea9dff 100644 --- a/app/graphql/connections/cursor_connection.rb +++ b/app/graphql/connections/cursor_connection.rb @@ -79,9 +79,16 @@ module Connections end def load_nodes_deprecated_order(limit, inverted) + payload = { + message: "CursorConnection: using deprecated order [#{Current.user.email}]", + user_id: Current.user.id + } + logger = Lograge.logger || Rails.logger + logger.info payload.to_json + expected_size = limit - 1 - if @deprecated_order == :desc && before.nil? + if before.nil? inverted = !inverted end diff --git a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb index 13d88a767..4d760601e 100644 --- a/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb +++ b/spec/controllers/api/v2/graphql_controller_stored_queries_spec.rb @@ -201,6 +201,9 @@ describe API::V2::GraphqlController do let(:end_cursor) { cursor_for(dossier2, order_column) } it { + allow(Rails.logger).to receive(:info) + expect(Rails.logger).to receive(:info).with("{\"message\":\"CursorConnection: using deprecated order [#{admin.email}]\",\"user_id\":#{admin.user.id}}") + expect(gql_errors).to be_nil expect(gql_data[:demarche][:dossiers][:nodes].size).to eq(2) expect(gql_data[:demarche][:dossiers][:pageInfo][:hasNextPage]).to be_truthy @@ -216,6 +219,9 @@ describe API::V2::GraphqlController do let(:end_cursor) { cursor_for(dossier, order_column) } it { + allow(Rails.logger).to receive(:info) + expect(Rails.logger).to receive(:info).with("{\"message\":\"CursorConnection: using deprecated order [#{admin.email}]\",\"user_id\":#{admin.user.id}}") + expect(gql_errors).to be_nil expect(gql_data[:demarche][:dossiers][:nodes].size).to eq(2) expect(gql_data[:demarche][:dossiers][:pageInfo][:hasNextPage]).to be_falsey @@ -232,6 +238,9 @@ describe API::V2::GraphqlController do let(:end_cursor) { cursor_for(dossier2, order_column) } it { + allow(Rails.logger).to receive(:info) + expect(Rails.logger).to receive(:info).with("{\"message\":\"CursorConnection: using deprecated order [#{admin.email}]\",\"user_id\":#{admin.user.id}}") + expect(gql_errors).to be_nil expect(gql_data[:demarche][:dossiers][:nodes].size).to eq(2) expect(gql_data[:demarche][:dossiers][:pageInfo][:hasNextPage]).to be_truthy