diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..27f048c --- /dev/null +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 28c90c0..0000000 --- a/.travis.yml +++ /dev/null @@ -1,41 +0,0 @@ ---- -language: ruby -cache: bundler -before_install: gem install bundler -v '~> 2.0' - -jobs: - include: - - rvm: 2.7.0 - gemfile: gemfiles/graphql_1.10.gemfile - env: - - GRAPHQL_RUBY_INTERPRETER=yes - - RAILS_VERSION=6.0 - - rvm: 2.7.0 - gemfile: gemfiles/graphql_1.10.gemfile - env: - - GRAPHQL_RUBY_INTERPRETER=no - - RAILS_VERSION=6.0 - - rvm: 2.6.5 - gemfile: gemfiles/graphql_1.9.gemfile - env: - - GRAPHQL_RUBY_INTERPRETER=yes - - RAILS_VERSION=6.0 - - rvm: 2.6.5 - gemfile: gemfiles/graphql_1.9.gemfile - env: - - GRAPHQL_RUBY_INTERPRETER=no - - RAILS_VERSION=6.0 - - rvm: 2.5.7 - gemfile: gemfiles/graphql_1.9.gemfile - env: - - GRAPHQL_RUBY_INTERPRETER=yes - - RAILS_VERSION=5.2 - - rvm: 2.5.7 - gemfile: gemfiles/graphql_1.9.gemfile - env: - - GRAPHQL_RUBY_INTERPRETER=no - - RAILS_VERSION=5.2 - - rvm: 2.4.9 - gemfile: gemfiles/graphql_1.8.gemfile - env: - - RAILS_VERSION=5.1 diff --git a/Appraisals b/Appraisals deleted file mode 100644 index 3cef181..0000000 --- a/Appraisals +++ /dev/null @@ -1,11 +0,0 @@ -appraise "graphql-1.8" do - gem "graphql", "~> 1.8.0" -end - -appraise "graphql-1.9" do - gem "graphql", "~> 1.9.0" -end - -appraise "graphql-1.10" do - gem "graphql", "~> 1.10.0" -end diff --git a/Gemfile b/Gemfile index 68baa9a..27fab34 100644 --- a/Gemfile +++ b/Gemfile @@ -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' diff --git a/Gemfile.lock b/Gemfile.lock index 044bcb9..5c40f49 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) @@ -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) @@ -66,7 +66,7 @@ PLATFORMS ruby DEPENDENCIES - activerecord + activerecord (~> 7.0) appraisal bundler (~> 2.0) graphql-preload! diff --git a/README.md b/README.md index 4ab5b59..175878b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Rakefile b/Rakefile deleted file mode 100644 index c24ed53..0000000 --- a/Rakefile +++ /dev/null @@ -1,6 +0,0 @@ -require 'bundler/gem_tasks' -require 'rspec/core/rake_task' - -RSpec::Core::RakeTask.new - -task default: :spec diff --git a/bin/setup b/bin/setup deleted file mode 100755 index dce67d8..0000000 --- a/bin/setup +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -IFS=$'\n\t' -set -vx - -bundle install - -# Do any other automated setup that you need to do here diff --git a/lib/graphql/preload/version.rb b/lib/graphql/preload/version.rb index 7e29b58..050f088 100644 --- a/lib/graphql/preload/version.rb +++ b/lib/graphql/preload/version.rb @@ -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 diff --git a/spec/graphql/preload_spec.rb b/spec/graphql/preload_spec.rb index d758e5c..3c552f4 100644 --- a/spec/graphql/preload_spec.rb +++ b/spec/graphql/preload_spec.rb @@ -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" diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6389fd8..8de204f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 =