Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first pass at :disabled option #56

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,13 @@ class QueryType < BaseObject
end
```


## Conditionally skip fragment_cache by disabling it

```ruby
cache_fragment(disabled: id < 5) { Post.find(id) }
```

## Cache storage and options

It's up to your to decide which caching engine to use, all you need is to configure the cache store:
Expand Down
2 changes: 2 additions & 0 deletions lib/graphql/fragment_cache/object_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def raw_value(obj)
def cache_fragment(object_to_cache = NO_OBJECT, **options, &block)
raise ArgumentError, "Block or argument must be provided" unless block_given? || object_to_cache != NO_OBJECT

return block_given? ? block.call : object_to_cache if options.delete(:disabled)

options[:object] = object_to_cache if object_to_cache != NO_OBJECT

context_to_use = options.delete(:context)
Expand Down
11 changes: 11 additions & 0 deletions spec/graphql/fragment_cache/field_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,15 @@ def cached_author
expect(::Post).to have_received(:find).once
end
end

context "when :disabled is true" do
let(:cache_fragment) { {disabled: true} }

it "do not use cache" do
expect(execute_query.dig("data", "post")).to eq({
"id" => "1",
"title" => "new option test"
})
end
end
end