diff --git a/CHANGELOG.md b/CHANGELOG.md index 86ab54a..6382ca2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## [0.3.0] - 2026-01-13 + +- Update gem to support Rails 8 for improved compatibility +- Add documentation enhancements and usage examples in AGENTS.md +- Update tests and documentation for better coverage and onboarding +- Fix warnings in tests related to string handling and deprecations +- Bump supported Ruby versions for broader compatibility +- Require ostruct as a runtime dependency for Ruby 3.4+ stdlib compatibility +- Clear out unnecessary extra slashes in query paths + ## [0.2.8] - 2025-12-17 - Add ostruct and logger as runtime dependencies for Ruby 3.4+ stdlib compatibility diff --git a/Gemfile.lock b/Gemfile.lock index 88175b4..f20e114 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - dato_cms_graphql (0.2.8) + dato_cms_graphql (0.3.0) activesupport (>= 7.1, < 9.0) graphql-client (>= 0.24.0, < 1.0) logger diff --git a/lib/dato_cms_graphql/rails/persistence.rb b/lib/dato_cms_graphql/rails/persistence.rb index ed78cf0..ae8c507 100644 --- a/lib/dato_cms_graphql/rails/persistence.rb +++ b/lib/dato_cms_graphql/rails/persistence.rb @@ -1,16 +1,30 @@ module DatoCmsGraphql::Rails module Persistence def self.persist_record(query, record) - Object.const_get(query.query_name) - .find_or_create_by( - locale: I18n.locale, - cms_id: record.id + return if record.id.nil? + + cms_id = record.id + existing = Record.find_by( + type: query.query_name, + locale: I18n.locale, + cms_id: cms_id + ) + if existing + existing.update( + render: query.render?, + permalink: (record.permalink if record.respond_to?(:permalink)), + cms_record: record.localized_raw_attributes ) - .update( + else + Record.create( + type: query.query_name, + locale: I18n.locale, + cms_id: cms_id, render: query.render?, permalink: (record.permalink if record.respond_to?(:permalink)), cms_record: record.localized_raw_attributes ) + end end def self.cache_data @@ -21,7 +35,7 @@ def self.cache_data record = query.get persist_record(query, record) else - query.all.each do |record| + query.all.uniq { |r| r.id }.each do |record| persist_record(query, record) end end diff --git a/lib/dato_cms_graphql/rails/railtie.rb b/lib/dato_cms_graphql/rails/railtie.rb index 1cbccc9..7d57665 100644 --- a/lib/dato_cms_graphql/rails/railtie.rb +++ b/lib/dato_cms_graphql/rails/railtie.rb @@ -5,8 +5,10 @@ class Railtie < ::Rails::Railtie load File.join(__dir__, "cache_task.rake") end initializer "dato_cms_graphql_railtie.configure_rails_initialization" do |app| - DatoCmsGraphql.path_to_queries = app.root.join("app", "queries") - puts DatoCmsGraphql.path_to_queries + unless ENV["TEST"] == "true" + DatoCmsGraphql.path_to_queries = app.root.join("app", "queries") + puts DatoCmsGraphql.path_to_queries + end end end end diff --git a/lib/dato_cms_graphql/version.rb b/lib/dato_cms_graphql/version.rb index 060ca74..9e354e4 100644 --- a/lib/dato_cms_graphql/version.rb +++ b/lib/dato_cms_graphql/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module DatoCmsGraphql - VERSION = "0.2.8" + VERSION = "0.3.0" end