DmitryTsepelev / graphql-ruby-persisted_queries

Persisted queries for graphql-ruby
MIT License
172 stars 20 forks source link

Adding Squish #28

Closed JanStevens closed 4 years ago

JanStevens commented 4 years ago

Implements #27

I did the first POC but I was a bit torn on the implementation, I see two possible ways:

  1. in resolver.rb when we call persist_query on the store (this is done in this MR)
  2. Expand the adapters so public methods persist_query actually delegates to store_presist_query and every store implements not persist_query but store_persist_query
class BaseStoreAdapter
  def fetch_query(hash)
     store_fetch_query(hash)
  end

  def save_query(hash, query)
     # Add squish here
     store_save_query(hash, query)
  end
end

class MemoryStoreAdapter < BaseStoreAdapter
  def initialize(_options)
    @storage = {}
  end

  def store_fetch_query(hash)
     @storage[hash]
  end

  def store_save_query(hash, query)
    @storage[hash] = query
  end
end
DmitryTsepelev commented 4 years ago

Great start! Both options should work, the only thing we should remember that one day someone will probably need to split up Resolver into ApolloResolver and RelayResolver🙂

JanStevens commented 4 years ago

Yea I don't think it's a great idea anymore. It might save space but it also messes up the hash integrity.

When things go wrong there is no way to calculate the right hash again that was send from the client if you only got your server side cache.