-
Notifications
You must be signed in to change notification settings - Fork 1
Description
In order to test pieces of application using this abstraction, is not always feasible to stub the methods to return the appropriate records every time. Especially when chaining where, includes and other query methods.
Ideally we need to add some means to intercept the queries, and the hard part is finding the correct place.
Gotchas found in the first quick and dirty attempts:
- application GraphQL records will have attributes such as
email, but the underlying network response hasemailAddress.emailAddress wherequeries are the most difficult: you might queryProductVariants.where(product_id: 123), but theProductVariantclass nor GraphQL type expose aproduct_id / productIdattribute/field to easily filter on the Ruby side
The ideal developer experience would be to define some sort of registry the queries will read the raw data from, so it can pass through the whole pipeline. There's friction: do we want to stub network responses or domain objects? Correct answer would be domain objects, but this makes a translation layer necessary:
stubbed domain objects -> registry format -> loader (test loader?) -> proper objects in application code
This brings more maintenance burden.
ActiveRecord skips all of this writing real records to the database, to mimic this we would need a shadow Shopify GraphQL schema to read from with stubbable data. This would be the most transparent, however feels like a major burden.