-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add integration test for querying with result cache
- Loading branch information
1 parent
bd5b781
commit e26bfe7
Showing
8 changed files
with
58 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
/tags | ||
|
||
/.idea/ | ||
/graphql-result_cache-*.gem |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class QueryType < GraphQL::Schema::Object | ||
field_class GraphQL::ResultCache::Field | ||
|
||
field :colors, [String], null: false, result_cache: true | ||
|
||
def colors | ||
%w[red yellow blue] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
class Schema < GraphQL::Schema | ||
query QueryType | ||
use GraphQL::ResultCache | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'spec_helper' | ||
require 'fixtures/query_type' | ||
require 'fixtures/schema' | ||
|
||
RSpec.describe 'query with result cache' do | ||
let(:cache_store) { double('cache_store') } | ||
let(:query_string) { 'query { colors }' } | ||
let(:result) { GraphQL::ResultCache::Result.new(Schema.execute(query_string)).value } | ||
|
||
before do | ||
allow(GraphQL::ResultCache).to receive(:cache).and_return cache_store | ||
end | ||
|
||
it 'query with cache missed' do | ||
cache_key = 'GraphQL:Result:colors' | ||
expect(cache_store).to receive(:exist?).with(cache_key).and_return false | ||
expect(cache_store).not_to receive(:read) | ||
expect(cache_store).to receive(:write).with(cache_key, %w[red yellow blue], expires_in: 3600) | ||
expect(result).to eq 'data' => { 'colors' => %w[red yellow blue] } | ||
end | ||
|
||
it 'queries with cache hits' do | ||
cache_key = 'GraphQL:Result:colors' | ||
expect(cache_store).to receive(:exist?).with(cache_key).and_return true | ||
expect(cache_store).to receive(:read).with(cache_key).and_return %w[red yellow] | ||
expect(cache_store).not_to receive(:write) | ||
expect(result).to eq 'data' => { 'colors' => %w[red yellow] } | ||
end | ||
end |