Apollo-compatible persisted queries for Strawberry.
Add PersistedQueriesExtension()
to your extensions.
import strawberry
from strawberry_persisted_queries import PersistedQueriesExtension
schema = strawberry.Schema(
query=Query,
extensions=[
PersistedQueriesExtension(),
],
)
For Django users, a Django cache backend is available. This uses the default cache set in Django.
from strawberry_persisted_queries.django_cache import DjangoPersistedQueryCache
PersistedQueriesExtension(cache_backend=DjangoPersistedQueryCache())
DictSafelist
can be used to require persisted queries to already be saved.
This can be used with a build tool to ensure only queries used within an app are available.
from strawberry_persisted_queries.safelisting import DictSafelist
PersistedQueriesExtension(safelist=DictSafelist({
'sha256Hash': 'query {...}',
}))
Custom cache backends allow using another cache for persisted queries, such as memcached or a database.
Custom cache backends can inherit from strawberry_persisted_queries.PersistedQueryCache
.
from strawberry_persisted_queries.cache import PersistedQueryCache
class MyCache(PersistedQueryCache):
def get(self, query_hash):
return cache.get(query_hash)
def set(self, query_hash, value):
cache.set(query_hash, value)
PersistedQueriesExtension(cache_backend=MyCache())