Skip to content

Custom Queries Development Pattern

tamsin johnson edited this page Jun 29, 2022 · 4 revisions

Introduction

In Valkyrie, Custom Queries are adapter-specific additions to standard Valkyrie Queries. They may only exist for one specific adapter. Reference: Custom Queries (Valkyrie documentation)

In Hyrax

Hyrax provides a number of custom queries intended for use with its metadata adapter's query service (Hyrax.query_service).

These queries are used throughout Hyrax's internals, so an implementation is required in order to use a new metadata adapter with Hyrax. For this reason, we provide default implementations of each of these queries that use only core Valkyrie queries. These implementations guarantee compatibility for all Valkyrie adapters that provide the core queries, but aren't intended to be high performance implementations. Hyrax may provide adapter specific implementations of these queries optimized for specific adapters (e.g. it does so for Wings); when it does so, we consider that adapter "supported". Applications considering using an unsupported adapter should evaluate the custom query implementations with their own performance needs in mind and, if appropriate, implement their own versions of these queries.

Hyrax.custom_queries is aliased to Valkyrie.config.metadata_adapter.query_service.custom_queries for convenience.

Code Locations

code location what happens there
lib/wings/setup.rb register custom queries in the wings metadata adapter (look for register_query_handler)
spec/spec_helper.rb register custom queries in other metadata adapters used for testing (look for register_query_handler)
`app/services/custom_queries/navigators/* defines custom queries that help with navigating from one object in the model to a related object. These are non-adapter specific and should work with all metadata adapters.
`app/services/custom_queries/* defines additional custom queries. These are non-adapter specific and should work with all metadata adapters.
`lib/wings/services/custom_queries/* defines custom queries that are optimized for wings adapter
Clone this wiki locally