Skip to content

Commit

Permalink
Merge branch 'graphiti-api:master' into fix_many_to_many_with_differe…
Browse files Browse the repository at this point in the history
…nt_association_names
  • Loading branch information
bguban authored Oct 29, 2024
2 parents 2743e37 + 4cad908 commit e627114
Show file tree
Hide file tree
Showing 37 changed files with 816 additions and 46 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,14 @@ jobs:
bundler-cache: true
- name: Run tests
run: bundle exec rspec
publish:
name: Release
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
needs: [test]
steps:
- name: Dispatch Release
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Generate New Release
token: ${{ secrets.GITHUB_TOKEN }}
36 changes: 36 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: Generate New Release

on:
workflow_dispatch:

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
persist-credentials: false
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1"
- name: Build
run: |
gem install bundler
git submodule update --init --recursive
bundle install --jobs 4 --retry 3
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: 14
- name: Install Dependencies
run: yarn install --frozen-lockfile
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GEM_HOST_API_KEY: ${{ secrets.GEM_HOST_API_KEY }}
run: node_modules/.bin/semantic-release
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/spec/reports/
/gemfiles/*.lock
/tmp/
node_modules
.byebug_history
spec/.rspec-examples
spec/dummy/log/*
Expand Down
2 changes: 1 addition & 1 deletion .standard.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fix: true
parallel: true
ruby_version: 2.4
ruby_version: 2.7

ignore:
- 'vendor/**/*'
Expand Down
120 changes: 119 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,122 @@
## Unreleased
graphiti changelog

## [1.7.5](https://github.com/graphiti-api/graphiti/compare/v1.7.4...v1.7.5) (2024-09-16)


### Bug Fixes

* Fixes error in version check for ActiveRecord adapter introduced in [#478](https://github.com/graphiti-api/graphiti/issues/478) ([#479](https://github.com/graphiti-api/graphiti/issues/479)) ([42c82c3](https://github.com/graphiti-api/graphiti/commit/42c82c397f20eb91c02835e518ff4c351c028ea7))

## [1.7.4](https://github.com/graphiti-api/graphiti/compare/v1.7.3...v1.7.4) (2024-09-11)


### Bug Fixes

* update ActiveRecord adapter w/ support for Rails 7.2+ ([#478](https://github.com/graphiti-api/graphiti/issues/478)) ([8313e33](https://github.com/graphiti-api/graphiti/commit/8313e3359f0dde28d9940867c7ded964db4c854d))

## [1.7.3](https://github.com/graphiti-api/graphiti/compare/v1.7.2...v1.7.3) (2024-06-26)


### Bug Fixes

* require OpenStruct explicitly ([#475](https://github.com/graphiti-api/graphiti/issues/475)) ([e0fa18a](https://github.com/graphiti-api/graphiti/commit/e0fa18a8d7f051e385e6e081f79f2ecae92a9260))

## [1.7.2](https://github.com/graphiti-api/graphiti/compare/v1.7.1...v1.7.2) (2024-06-11)


### Bug Fixes

* require necessary ActiveSupport parts in proper order ([bb2a488](https://github.com/graphiti-api/graphiti/commit/bb2a48874a6533522df6eb027d0df8ec14c80a20))

## [1.7.1](https://github.com/graphiti-api/graphiti/compare/v1.7.0...v1.7.1) (2024-04-18)


### Bug Fixes

* properly display .find vs .all in debugger statements ([d2a7a03](https://github.com/graphiti-api/graphiti/commit/d2a7a038a649818979d52ccd898e68dba78b051f))
* rescue error from sideloads updated_at calculation, defaulting to the current time ([661e3b5](https://github.com/graphiti-api/graphiti/commit/661e3b5212e2649870a200067d0d5d52fa962637))

# [1.7.0](https://github.com/graphiti-api/graphiti/compare/v1.6.4...v1.7.0) (2024-03-27)


### Features

* Add support for caching renders in Graphiti, and better support using etags and stale? in the controller ([#424](https://github.com/graphiti-api/graphiti/issues/424)) ([8bae50a](https://github.com/graphiti-api/graphiti/commit/8bae50ab82559e2644d506e16a4f715effd89317))

## [1.6.4](https://github.com/graphiti-api/graphiti/compare/v1.6.3...v1.6.4) (2024-03-27)

## [1.6.3](https://github.com/graphiti-api/graphiti/compare/v1.6.2...v1.6.3) (2024-03-26)


### Bug Fixes

* Remove thread pool executor logic until we get a better handle on what's causing thread pool hangs. refs [#469](https://github.com/graphiti-api/graphiti/issues/469) ([7941b6f](https://github.com/graphiti-api/graphiti/commit/7941b6f75ce1001b034ed6e83c148b893e9f3d99)), closes [#471](https://github.com/graphiti-api/graphiti/issues/471) [#470](https://github.com/graphiti-api/graphiti/issues/470)

## [1.6.2](https://github.com/graphiti-api/graphiti/compare/v1.6.1...v1.6.2) (2024-03-22)


### Bug Fixes

* thread pool scope and mutex need to be global across all instances of Scope for it to be a global thread pool ([#471](https://github.com/graphiti-api/graphiti/issues/471)) ([51fb51c](https://github.com/graphiti-api/graphiti/commit/51fb51c31f0043d98aa07f689a8cf8c758fa823b))

## [1.6.1](https://github.com/graphiti-api/graphiti/compare/v1.6.0...v1.6.1) (2024-03-22)


### Bug Fixes

* correct thread-pool mutex logic which was causing a deadlock ([0400ab0](https://github.com/graphiti-api/graphiti/commit/0400ab0d97a1382b66b5295fdc7aa7db680e77cc))

# [1.6.0](https://github.com/graphiti-api/graphiti/compare/v1.5.3...v1.6.0) (2024-03-20)


### Features

* add thread pool and concurrency_max_threads configuration option ([#470](https://github.com/graphiti-api/graphiti/issues/470)) ([697d761](https://github.com/graphiti-api/graphiti/commit/697d76172adec24cd7e7522300c8335233fdcc36))

## [1.5.3](https://github.com/graphiti-api/graphiti/compare/v1.5.2...v1.5.3) (2024-03-18)


### Bug Fixes

* leverage ruby-2.7 parameter forwarding ([#431](https://github.com/graphiti-api/graphiti/issues/431)) ([ae09a46](https://github.com/graphiti-api/graphiti/commit/ae09a464b2156742bb093537deac0578a1a3e40e))
* prevent :id stripping when :id not in path ([#447](https://github.com/graphiti-api/graphiti/issues/447)) ([e1dd811](https://github.com/graphiti-api/graphiti/commit/e1dd811283f6e6fe7a36b925934df0ecbb4d3411))

## [1.5.2](https://github.com/graphiti-api/graphiti/compare/v1.5.1...v1.5.2) (2024-03-18)


### Bug Fixes

* Enum should allow the conventionally case-sensitive operators ([#434](https://github.com/graphiti-api/graphiti/issues/434)) ([56d34fd](https://github.com/graphiti-api/graphiti/commit/56d34fd4801bc32c13d64aca880b82b717b2ab81))

## [1.5.1](https://github.com/graphiti-api/graphiti/compare/v1.5.0...v1.5.1) (2024-03-18)


### Bug Fixes

* polymorphic `on` expects a symbol ([#433](https://github.com/graphiti-api/graphiti/issues/433)) ([4e58702](https://github.com/graphiti-api/graphiti/commit/4e587021265323bd0b170b57e9c7aecaa7f826d7))

# [1.5.0](https://github.com/graphiti-api/graphiti/compare/v1.4.0...v1.5.0) (2024-03-18)


### Features

* add before_sideload hook ([#371](https://github.com/graphiti-api/graphiti/issues/371)) ([f68b61f](https://github.com/graphiti-api/graphiti/commit/f68b61ff09ec61ecf23acc5bc37d0accba14aeed))

## 1.4.0, Sun March 17th 2024
Features:
- [461](https://github.com/graphiti-api/graphiti/pull/461), [463](https://github.com/graphiti-api/graphiti/pull/463) Add support for Rails 7.1 + Ruby 3.2 + Ruby 3.3

Fixes:
- [464](https://github.com/graphiti-api/graphiti/pull/464) Check for url presence before trying to append
- [407](https://github.com/graphiti-api/graphiti/pull/407) Sort types in generated schema
- [421](https://github.com/graphiti-api/graphiti/pull/421) Re-use resource class for remote sideloads to avoid memory leak
- [452](https://github.com/graphiti-api/graphiti/pull/452) Resolve inconsistency for filters containing curly brackets
- [446](https://github.com/graphiti-api/graphiti/pull/446) Fix private call

## 1.3.9, May 25th 2022
Use an options hash for log subscriber instead of positional arguments

## 1.x ??

Features:
- [329](https://github.com/graphiti-api/graphiti/pull/329) Propagate `extra_fields` to related resource links.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
![Build Status](https://travis-ci.org/graphiti-api/graphiti.svg?branch=master)
[![CI](https://github.com/graphiti-api/graphiti/actions/workflows/ci.yml/badge.svg)](https://github.com/graphiti-api/graphiti/actions/workflows/ci.yml)
[![Gem Version](https://badge.fury.io/rb/graphiti.svg)](https://badge.fury.io/rb/graphiti)
[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)

<p align="center">
<a href="https://www.graphiti.dev/guides">
Expand Down
2 changes: 1 addition & 1 deletion graphiti.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.required_ruby_version = ">= 2.6"
spec.required_ruby_version = ">= 2.7"

spec.add_dependency "jsonapi-serializable", "~> 0.3.0"
spec.add_dependency "jsonapi-renderer", "~> 0.2", ">= 0.2.2"
Expand Down
17 changes: 15 additions & 2 deletions lib/graphiti.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
require "json"
require "forwardable"
require "uri"
require "ostruct" unless defined?(::OpenStruct)

require "active_support/version"
require "active_support/deprecation"
require "active_support/deprecator" if ::ActiveSupport.version >= Gem::Version.new("7.1")
require "active_support/core_ext/string"
require "active_support/core_ext/enumerable"
require "active_support/core_ext/class/attribute"
require "active_support/core_ext/hash/conversions" # to_xml
require "active_support/concern"
require "active_support/time"
require "active_support/deprecation"

require "dry-types"
require "graphiti_errors"
Expand Down Expand Up @@ -106,6 +110,14 @@ def self.setup!
r.apply_sideloads_to_serializer
end
end

def self.cache=(val)
@cache = val
end

def self.cache
@cache
end
end

require "graphiti/version"
Expand Down Expand Up @@ -137,7 +149,6 @@ def self.setup!
require "graphiti/request_validator"
require "graphiti/request_validators/validator"
require "graphiti/request_validators/update_validator"
require "graphiti/query"
require "graphiti/scope"
require "graphiti/deserializer"
require "graphiti/renderer"
Expand Down Expand Up @@ -176,7 +187,9 @@ def self.setup!
require "graphiti/extensions/boolean_attribute"
require "graphiti/extensions/temp_id"
require "graphiti/serializer"
require "graphiti/query"
require "graphiti/debugger"
require "graphiti/util/cache_debug"

if defined?(ActiveRecord)
require "graphiti/adapters/active_record"
Expand Down
2 changes: 1 addition & 1 deletion lib/graphiti/adapters/abstract.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def self.default_operators
:not_match
],
uuid: [:eq, :not_eq],
enum: [:eq, :not_eq],
enum: [:eq, :not_eq, :eql, :not_eql],
integer_id: numerical_operators,
integer: numerical_operators,
big_decimal: numerical_operators,
Expand Down
8 changes: 7 additions & 1 deletion lib/graphiti/adapters/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def filter_eq(scope, attribute, value)
alias_method :filter_boolean_eq, :filter_eq
alias_method :filter_uuid_eq, :filter_eq
alias_method :filter_enum_eq, :filter_eq
alias_method :filter_enum_eql, :filter_eq

def filter_not_eq(scope, attribute, value)
scope.where.not(attribute => value)
Expand All @@ -37,6 +38,7 @@ def filter_not_eq(scope, attribute, value)
alias_method :filter_boolean_not_eq, :filter_not_eq
alias_method :filter_uuid_not_eq, :filter_not_eq
alias_method :filter_enum_not_eq, :filter_not_eq
alias_method :filter_enum_not_eql, :filter_not_eq

def filter_string_eq(scope, attribute, value, is_not: false)
column = column_for(scope, attribute)
Expand Down Expand Up @@ -302,7 +304,11 @@ def destroy(model_instance)
end

def close
::ActiveRecord::Base.clear_active_connections!
if ::ActiveRecord.version > "7.2"
::ActiveRecord::Base.connection_handler.clear_active_connections!
else
::ActiveRecord::Base.clear_active_connections!
end
end

def can_group?
Expand Down
13 changes: 13 additions & 0 deletions lib/graphiti/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class Configuration
attr_accessor :pagination_links
attr_accessor :typecast_reads
attr_accessor :raise_on_missing_sidepost
attr_accessor :before_sideload

attr_reader :debug, :debug_models

attr_writer :schema_path
attr_writer :cache_rendering

# Set defaults
# @api private
Expand All @@ -31,6 +33,7 @@ def initialize
@pagination_links = false
@typecast_reads = true
@raise_on_missing_sidepost = true
@cache_rendering = false
self.debug = ENV.fetch("GRAPHITI_DEBUG", true)
self.debug_models = ENV.fetch("GRAPHITI_DEBUG_MODELS", false)

Expand All @@ -51,6 +54,16 @@ def initialize
end
end

def cache_rendering?
use_caching = @cache_rendering && Graphiti.cache.respond_to?(:fetch)

use_caching.tap do |use|
if @cache_rendering && !Graphiti.cache&.respond_to?(:fetch)
raise "You must configure a cache store in order to use cache_rendering. Set Graphiti.cache = Rails.cache, for example."
end
end
end

def schema_path
@schema_path ||= raise("No schema_path defined! Set Graphiti.config.schema_path to save your schema.")
end
Expand Down
31 changes: 27 additions & 4 deletions lib/graphiti/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def on_data(name, start, stop, id, payload)
json[:sideload] = sideload.name
end
if params
query = "#{payload[:resource].class.name}.all(#{JSON.pretty_generate(params)}).data"
query = "#{payload[:resource].class.name}.#{payload[:action]}(#{JSON.pretty_generate(params)}).data"
logs << [query, :cyan, true]
logs << ["The error occurred when running the above query. Copy/paste it into a rake task or Rails console session to reproduce. Keep in mind you may have to set context.", :yellow, true]
else
Expand Down Expand Up @@ -64,7 +64,7 @@ def on_data(name, start, stop, id, payload)
query = if sideload.class.scope_proc
"#{payload[:resource].class.name}: Manual sideload via .scope"
else
"#{payload[:resource].class.name}.all(#{params.inspect})"
"#{payload[:resource].class.name}.#{payload[:action]}(#{params.inspect})"
end
logs << [" #{query}", :cyan, true]
json[:query] = query
Expand All @@ -82,7 +82,7 @@ def on_data(name, start, stop, id, payload)
title = "Top Level Data Retrieval (+ sideloads):"
logs << [title, :green, true]
json[:title] = title
query = "#{payload[:resource].class.name}.all(#{params.inspect})"
query = "#{payload[:resource].class.name}.#{payload[:action]}(#{params.inspect})"
logs << [query, :cyan, true]
json[:query] = query
logs << ["Returned Models: #{results}"] if debug_models
Expand All @@ -98,7 +98,30 @@ def on_render(name, start, stop, id, payload)
took = ((stop - start) * 1000.0).round(2)
logs << [""]
logs << ["=== Graphiti Debug", :green, true]
logs << ["Rendering:", :green, true]
if payload[:proxy]&.cached? && Graphiti.config.cache_rendering?
logs << ["Rendering (cached):", :green, true]

Graphiti::Util::CacheDebug.new(payload[:proxy]).analyze do |cache_debug|
logs << ["Cache key for #{cache_debug.name}", :blue, true]
logs << if cache_debug.volatile?
[" \\_ volatile | Request count: #{cache_debug.request_count} | Hit count: #{cache_debug.hit_count}", :red, true]
else
[" \\_ stable | Request count: #{cache_debug.request_count} | Hit count: #{cache_debug.hit_count}", :blue, true]
end

if cache_debug.changed_key?
logs << [" [x] cache key changed #{cache_debug.last_version[:etag]} -> #{cache_debug.current_version[:etag]}", :red]
logs << [" removed: #{cache_debug.removed_segments}", :red]
logs << [" added: #{cache_debug.added_segments}", :red]
elsif cache_debug.new_key?
logs << [" [+] cache key added #{cache_debug.current_version[:etag]}", :red, true]
else
logs << [" [✓] #{cache_debug.current_version[:etag]}", :green, true]
end
end
else
logs << ["Rendering:", :green, true]
end
logs << ["Took: #{took}ms", :magenta, true]
end
end
Expand Down
Loading

0 comments on commit e627114

Please sign in to comment.