Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI
on: push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0

- name: Configure Bundler
run: bundle config set rubygems.pkg.github.com "${{ secrets.KRYSTAL_GITHUB_PACKAGE_READ_KEY }}"

- name: Install dependencies
run: bundle install

- name: Run tests
run: bundle exec rspec

release:
runs-on: ubuntu-latest
needs: [test]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
steps:
- uses: actions/checkout@master

- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 3.0

- name: Export version from tag name
run: echo ${GITHUB_REF/refs\/tags\//} > VERSION

- name: Build Gem
run: gem build *.gemspec

- name: Setup credentials
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- ":github: Bearer ${GITHUB_API_KEY}\n" >> $HOME/.gem/credentials
env:
GITHUB_API_KEY: ${{secrets.GITHUB_TOKEN}}

- name: Publish to GPR
run: |
gem push --key github --host https://rubygems.pkg.github.com/krystal *.gem
41 changes: 0 additions & 41 deletions .travis.yml

This file was deleted.

11 changes: 0 additions & 11 deletions Appraisals

This file was deleted.

2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in graphql-preload.gemspec
gemspec

gem 'activerecord', ENV['RAILS_VERSION'] && "~> #{ENV['RAILS_VERSION']}.0"
gem 'activerecord', "~> 7.0"

# See https://github.com/nepalez/rspec-sqlimit/issues/13
gem 'rspec-sqlimit'
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
graphql-preload (2.1.0)
graphql-preload (0.0.0.dev)
activerecord (>= 7)
graphql (>= 1.8, < 2)
graphql-batch (~> 0.3)
Expand All @@ -27,8 +27,8 @@ GEM
coderay (1.1.2)
concurrent-ruby (1.2.2)
diff-lcs (1.5.0)
graphql (1.10.5)
graphql-batch (0.4.2)
graphql (1.12.24)
graphql-batch (0.4.3)
graphql (>= 1.3, < 2)
promise.rb (~> 0.7.2)
i18n (1.13.0)
Expand Down Expand Up @@ -66,7 +66,7 @@ PLATFORMS
ruby

DEPENDENCIES
activerecord
activerecord (~> 7.0)
appraisal
bundler (~> 2.0)
graphql-preload!
Expand Down
22 changes: 2 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,11 @@ class PostType < GraphQL::Schema::Object
end
```

### `preload_scope`

Starting with Rails 4.1, you can scope your preloaded records by passing a valid scope to [`ActiveRecord::Associations::Preloader`](https://apidock.com/rails/v4.1.8/ActiveRecord/Associations/Preloader/preload). Scoping can improve performance by reducing the number of models to be instantiated and can help with certain business goals (e.g., only returning records that have not been soft deleted).

This functionality is surfaced through the `preload_scope` option:

```ruby
class UserType < GraphQL::Schema::Object
field :posts, [PostType], null: false,
preload: :posts,
preload_scope: ->(*) { Post.order(rating: :desc) }
end
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing
After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

Bug reports and pull requests are welcome on GitHub at https://github.com/ConsultingMD/graphql-preload.
To release a new version of the gem, create a new tag and push it to GitHub.

## License

Expand Down
6 changes: 0 additions & 6 deletions Rakefile

This file was deleted.

8 changes: 0 additions & 8 deletions bin/setup

This file was deleted.

9 changes: 8 additions & 1 deletion lib/graphql/preload/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
module GraphQL
module Preload
VERSION = '2.1.0'.freeze

VERSION_FILE_ROOT = File.expand_path('../../VERSION', __dir__)
if File.file?(VERSION_FILE_ROOT)
VERSION = File.read(VERSION_FILE_ROOT).strip.sub(/\Av/, '')
else
VERSION = '0.0.0.dev'
end

end
end
5 changes: 4 additions & 1 deletion spec/graphql/preload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@
end
end

context "modern class-based GraphQL schema" do
# GraphQL v2 is not supported with these changes, so I've disabled the tests. When we want
# to start using v2 then we should try using this fork as a base instead:
# https://github.com/ConsultingMD/graphql-preload/pull/38
xcontext "modern class-based GraphQL schema" do
let(:schema) { PreloadSchema }

include_examples "test suite"
Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# frozen_string_literal: true

require "bundler/setup"
require "graphql/preload"
require "rspec-sqlimit"
require "pry"
require "yaml"

TESTING_GRAPHQL_RUBY_INTERPRETER =
Expand Down