graphql-batch 0.6.0 → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: afe26d607949310c337c3f88cb6f356ccd51923d841fa1e7e8840f0fa5b34012
4
- data.tar.gz: 1f45b62562ef558a6f6b59479b198fdb548b8f03f061ebb0e6c51b6cff74c6b4
3
+ metadata.gz: 6fb5c2ff59d27a3474412dd661921db243b66b66263e581ff391c5285d60101b
4
+ data.tar.gz: f8237942cd0edd505c901176695502acf346c16778529cf64aa0c1103d193e1d
5
5
  SHA512:
6
- metadata.gz: 7416844cffe48e01ca8640382e831cafdd1d64efcbcb927677a2d8833a3883400806cb94f16c8057d9c0f15ca543640b8084ba7616bb2b7376fa21f75a366179
7
- data.tar.gz: 7473cb5eb3893fc61b0be940c28a8582a3316e912909ec7d2c8d1aeb9f01b1011b88c3ca754330f48152276ed0463e39508b625b5351800a53254dfc86669e5f
6
+ metadata.gz: a2cd9a5c2a13eeed2fde1d4065ab0158e05d3a2af767c954789004ac72084b26e54cd972ccedfe9da27eca34201985f5b9841ca78d328c76d7db3b7b39a1df15
7
+ data.tar.gz: 35de2220871a142aab7b49e918b5526cddcbcc28c417849c383b377f238b5b6802b55abbdf91a37118b3c3de50979c1b6e4eb9bcd138557a505bf54fab432397
@@ -0,0 +1,24 @@
1
+ version: 2
2
+ registries:
3
+ ruby-shopify:
4
+ type: rubygems-server
5
+ url: https://pkgs.shopify.io/basic/gems/ruby
6
+ username: ${{secrets.RUBYGEMS_SERVER_PKGS_SHOPIFY_IO_USERNAME}}
7
+ password: ${{secrets.RUBYGEMS_SERVER_PKGS_SHOPIFY_IO_PASSWORD}}
8
+ github-com:
9
+ type: git
10
+ url: https://github.com
11
+ username: ${{secrets.DEPENDENCIES_GITHUB_USER}}
12
+ password: ${{secrets.DEPENDENCIES_GITHUB_TOKEN}}
13
+ updates:
14
+ - package-ecosystem: github-actions
15
+ directory: "/"
16
+ schedule:
17
+ interval: weekly
18
+ - package-ecosystem: bundler
19
+ directory: "/"
20
+ schedule:
21
+ interval: weekly
22
+ open-pull-requests-limit: 100
23
+ insecure-external-code-execution: allow
24
+ registries: "*"
@@ -10,16 +10,11 @@ jobs:
10
10
  strategy:
11
11
  fail-fast: false
12
12
  matrix:
13
- ruby: [2.7, 3.1, 3.3]
14
- graphql_version: ['~> 1.12.18', '~> 1.13', '~> 2.0']
15
- include:
16
- - ruby: 2.4
17
- graphql_version: '~> 1.12.18'
18
- - ruby: 2.4
19
- graphql_version: '~> 1.13'
13
+ ruby: [2.7, 3.0, 3.1, 3.2, 3.3]
14
+ graphql_version: ['~> 1.13', '~> 2.0']
20
15
  steps:
21
- - uses: actions/checkout@v2
22
- - uses: ruby/setup-ruby@v1
16
+ - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
17
+ - uses: ruby/setup-ruby@44511735964dcb71245e7e55f72539531f7bc0eb # v1.257.0
23
18
  with:
24
19
  bundler-cache: true
25
20
  ruby-version: ${{ matrix.ruby }}
@@ -0,0 +1,23 @@
1
+ name: Dependabot auto-merge
2
+ on: pull_request_target
3
+
4
+ permissions:
5
+ pull-requests: write
6
+ contents: write
7
+
8
+ jobs:
9
+ dependabot:
10
+ runs-on: ubuntu-latest
11
+ if: ${{ github.event.pull_request.user.login == 'dependabot[bot]' }}
12
+ steps:
13
+ - name: Dependabot metadata
14
+ id: metadata
15
+ uses: dependabot/fetch-metadata@08eff52bf64351f401fb50d4972fa95b9f2c2d1b # v2.4.0
16
+ with:
17
+ github-token: "${{ secrets.GITHUB_TOKEN }}"
18
+ - name: Enable auto-merge for Dependabot PRs
19
+ if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-patch' }}
20
+ run: gh pr merge --auto --merge "$PR_URL"
21
+ env:
22
+ PR_URL: ${{ github.event.pull_request.html_url }}
23
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
data/.rubocop.yml CHANGED
@@ -6,6 +6,5 @@ inherit_from:
6
6
 
7
7
  AllCops:
8
8
  SuggestExtensions: false
9
- TargetRubyVersion: 2.7
10
9
  Exclude:
11
10
  - vendor/**/*
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.1
data/Gemfile CHANGED
@@ -3,7 +3,5 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  gem 'graphql', ENV['GRAPHQL_VERSION'] if ENV['GRAPHQL_VERSION']
6
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
7
- gem 'rubocop', '~> 1.12.0', require: false
8
- gem "rubocop-shopify", '~> 1.0.7', require: false
9
- end
6
+ gem 'rubocop', '~> 1.61.0', require: false
7
+ gem "rubocop-shopify", '~> 1.0.7', require: false
data/Rakefile CHANGED
@@ -9,11 +9,9 @@ end
9
9
 
10
10
  task(default: :test)
11
11
 
12
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.4.0')
13
- task :rubocop do
14
- require 'rubocop/rake_task'
15
- RuboCop::RakeTask.new
16
- end
17
-
18
- task(default: :rubocop)
12
+ task :rubocop do
13
+ require 'rubocop/rake_task'
14
+ RuboCop::RakeTask.new
19
15
  end
16
+
17
+ task(default: :rubocop)
@@ -0,0 +1,90 @@
1
+ ####
2
+ # This is a loader for Active Storage attachments,
3
+ # a little bit more complex than the `active_storage_loader.rb` example
4
+ # because it supports STI (Single Table Inheritance) models where the
5
+ # `has_one_attached` or `has_many_attached` is defined on any of the ancestor classes of the model.
6
+
7
+ ####
8
+ # The model with an attached image and many attached pictures:
9
+ ####
10
+
11
+ # class Event < ApplicationRecord
12
+ # has_one_attached :image
13
+ # has_many_attached :pictures
14
+ # end
15
+
16
+ ####
17
+ # An example data type using the AttachmentLoader:
18
+ ####
19
+
20
+ # class Types::EventType < Types::BaseObject
21
+ # graphql_name 'Event'
22
+ #
23
+ # field :id, ID, null: false
24
+ # field :image, String, null: true
25
+ # field :pictures, String, null: true
26
+ #
27
+ # def image
28
+ # AttachmentLoader.for(:Event, :image).load(object.id).then do |image|
29
+ # Rails.application.routes.url_helpers.url_for(
30
+ # image.variant({ quality: 75 })
31
+ # )
32
+ # end
33
+ # end
34
+ #
35
+ # def pictures
36
+ # AttachmentLoader.for(:Event, :pictures, association_type: :has_many_attached).load(object.id).then do |pictures|
37
+ # pictures.map do |picture|
38
+ # Rails.application.routes.url_helpers.url_for(
39
+ # picture.variant({ quality: 75 })
40
+ # )
41
+ # end
42
+ # end
43
+ # end
44
+ # end
45
+
46
+ class ActiveStorageLoader < GraphQL::Batch::Loader
47
+ attr_reader :record_type, :attachment_name, :association_type
48
+
49
+ def initialize(record_type, attachment_name, association_type: :has_one_attached)
50
+ super()
51
+ @record_type = record_type
52
+ @attachment_name = attachment_name
53
+ @association_type = association_type
54
+ end
55
+
56
+ def perform(record_ids)
57
+ attachments = ActiveStorage::Attachment.includes(:blob, :record).where(
58
+ record_type: ancestors_record_types, record_id: record_ids, name: attachment_name
59
+ )
60
+
61
+ if @association_type == :has_one_attached
62
+ attachments.each do |attachment|
63
+ fulfill(attachment.record_id, attachment)
64
+ end
65
+
66
+ record_ids.each { |id| fulfill(id, nil) unless fulfilled?(id) }
67
+ else
68
+ record_ids.each do |record_id|
69
+ fulfill(record_id, attachments.select { |attachment| attachment.record_id == record_id })
70
+ end
71
+ end
72
+ end
73
+
74
+ private
75
+
76
+ def ancestors_record_types
77
+ # Get all ancestor classes of record_type that are descendants of ActiveRecord::Base
78
+ # This is necessary because in a Single Table Inheritance (STI) setup,
79
+ # the `has_one_attached` or `has_many_attached`
80
+ # could be defined on any of the ancestor classes of the model, not just the model itself,
81
+ # which determines whether the `record_type` string is stored as the model's class name
82
+ # or the ancestor's class name.
83
+ # So we for any of the ancestor classes to ensure we don't miss the attachment
84
+ # we are looking for:
85
+
86
+ @record_type.to_s.constantize.ancestors.select do |ancestor|
87
+ ancestor < ActiveRecord::Base
88
+ end.map(&:to_s)
89
+ end
90
+ end
@@ -10,6 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.homepage = "https://github.com/Shopify/graphql-batch"
11
11
  spec.license = "MIT"
12
12
 
13
+ spec.required_ruby_version = ">= 2.7"
14
+
13
15
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
16
  spec.bindir = "exe"
15
17
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -17,7 +19,7 @@ Gem::Specification.new do |spec|
17
19
 
18
20
  spec.metadata['allowed_push_host'] = "https://rubygems.org"
19
21
 
20
- spec.add_runtime_dependency "graphql", ">= 1.12.18", "< 3"
22
+ spec.add_runtime_dependency "graphql", ">= 1.13", "< 3"
21
23
  spec.add_runtime_dependency "promise.rb", "~> 0.7.2"
22
24
 
23
25
  spec.add_development_dependency "byebug" if RUBY_ENGINE == 'ruby'
@@ -66,7 +66,7 @@ module GraphQL::Batch
66
66
  cache[cache_key(key)] ||= ::Promise.resolve(value).tap { |p| p.source = self }
67
67
  end
68
68
 
69
- def resolve #:nodoc:
69
+ def resolve # :nodoc:
70
70
  return if resolved?
71
71
  load_keys = queue
72
72
  @queue = nil
@@ -86,7 +86,7 @@ module GraphQL::Batch
86
86
  end
87
87
 
88
88
  # For Promise#sync
89
- def wait #:nodoc:
89
+ def wait # :nodoc:
90
90
  if executor
91
91
  executor.resolve(self)
92
92
  else
@@ -1,5 +1,5 @@
1
1
  module GraphQL
2
2
  module Batch
3
- VERSION = "0.6.0"
3
+ VERSION = "0.6.1"
4
4
  end
5
5
  end
data/lib/graphql/batch.rb CHANGED
@@ -26,7 +26,7 @@ module GraphQL
26
26
  if schema_defn.mutation
27
27
  require_relative "batch/mutation_field_extension"
28
28
 
29
- schema_defn.mutation.fields.each do |name, field|
29
+ schema_defn.mutation.all_field_definitions.map do |field|
30
30
  field.extension(GraphQL::Batch::MutationFieldExtension)
31
31
  end
32
32
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-batch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Thacker-Smith
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-02-23 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: graphql
@@ -16,7 +15,7 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 1.12.18
18
+ version: '1.13'
20
19
  - - "<"
21
20
  - !ruby/object:Gem::Version
22
21
  version: '3'
@@ -26,7 +25,7 @@ dependencies:
26
25
  requirements:
27
26
  - - ">="
28
27
  - !ruby/object:Gem::Version
29
- version: 1.12.18
28
+ version: '1.13'
30
29
  - - "<"
31
30
  - !ruby/object:Gem::Version
32
31
  version: '3'
@@ -86,18 +85,20 @@ dependencies:
86
85
  - - ">="
87
86
  - !ruby/object:Gem::Version
88
87
  version: '0'
89
- description:
90
88
  email:
91
89
  - gems@shopify.com
92
90
  executables: []
93
91
  extensions: []
94
92
  extra_rdoc_files: []
95
93
  files:
94
+ - ".github/dependabot.yml"
96
95
  - ".github/workflows/ci.yml"
97
96
  - ".github/workflows/cla.yml"
97
+ - ".github/workflows/dependabot_auto_merge.yml"
98
98
  - ".gitignore"
99
99
  - ".rubocop.yml"
100
100
  - ".rubocop_todo.yml"
101
+ - ".ruby-version"
101
102
  - CONTRIBUTING.md
102
103
  - Gemfile
103
104
  - LICENSE.txt
@@ -106,6 +107,7 @@ files:
106
107
  - bin/console
107
108
  - bin/setup
108
109
  - examples/active_storage_loader.rb
110
+ - examples/active_storage_loader_sti.rb
109
111
  - examples/association_loader.rb
110
112
  - examples/http_loader.rb
111
113
  - examples/record_loader.rb
@@ -122,7 +124,6 @@ licenses:
122
124
  - MIT
123
125
  metadata:
124
126
  allowed_push_host: https://rubygems.org
125
- post_install_message:
126
127
  rdoc_options: []
127
128
  require_paths:
128
129
  - lib
@@ -130,15 +131,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
131
  requirements:
131
132
  - - ">="
132
133
  - !ruby/object:Gem::Version
133
- version: '0'
134
+ version: '2.7'
134
135
  required_rubygems_version: !ruby/object:Gem::Requirement
135
136
  requirements:
136
137
  - - ">="
137
138
  - !ruby/object:Gem::Version
138
139
  version: '0'
139
140
  requirements: []
140
- rubygems_version: 3.5.6
141
- signing_key:
141
+ rubygems_version: 3.7.2
142
142
  specification_version: 4
143
143
  summary: A query batching executor for the graphql gem
144
144
  test_files: []