Hi 👋. Love that graphiti exists!
Scenario: layering in a graphiti-powered api over a legacy (non rails-conventional) database.
Our thinking is that the ActiveRecord objects should remain as close to the legacy db as possible (ie, we probably don't want to define too many alias_attributes, for instance). This way the AR models are honest about what the db schema looks like. On the flip side, the REST api should be designed to be more "ideal" in how the domain objects are represented.
To that end, it's presumably the job of the Resource then, to map the "ideal api-level" names/properties to the legacy forms on the AR models. Does this feel like the right approach without setting up for too much pain?
More particular question, what to do about non-conventional primary keys.
Assuming:
class Thing < ApplicationRecord
self.primary_key = "thingsid"
end
Our feeling is that we would like ThingResource to still expose id as the primary key at the api layer, since that is "ideal". (And presumably, exposing non-conventional primary keys in the api layer would cause a lot of pain to the api clients and their ability to use jsonapi.org libraries.)
When we do ThingResource.find(id: 42), we get the incorrect SQL query:
SELECT `things`.* FROM `things` WHERE `things`.`id` = 42 LIMIT 1`
It seems graphiti is not respecting Thing's custom primary key. (Which also implies the active record adapter backend is not using ActiveRecord's Thing.find which would respect the customized primary key.
So, what is graphiti's opinion on the best place to define these customizations that reconciles our desire to expose the more "ideal/conventional" domain api while at the same time not setting ourselves up for a world of hurt with graphiti's resource associations and the frontend/mobile api clients (read: jsonapi spec libs). (Keeping in mind this is a legacy database so non-conventional PKeys, FKeys, and whatnot will be the rule, not the exception.)
Hi 👋. Love that graphiti exists!
Scenario: layering in a graphiti-powered api over a legacy (non rails-conventional) database.
Our thinking is that the ActiveRecord objects should remain as close to the legacy db as possible (ie, we probably don't want to define too many
alias_attributes, for instance). This way the AR models are honest about what the db schema looks like. On the flip side, the REST api should be designed to be more "ideal" in how the domain objects are represented.To that end, it's presumably the job of the Resource then, to map the "ideal api-level" names/properties to the legacy forms on the AR models. Does this feel like the right approach without setting up for too much pain?
More particular question, what to do about non-conventional primary keys.
Assuming:
Our feeling is that we would like
ThingResourceto still exposeidas the primary key at the api layer, since that is "ideal". (And presumably, exposing non-conventional primary keys in the api layer would cause a lot of pain to the api clients and their ability to use jsonapi.org libraries.)When we do
ThingResource.find(id: 42), we get the incorrect SQL query:It seems graphiti is not respecting
Thing's custom primary key. (Which also implies the active record adapter backend is not using ActiveRecord'sThing.findwhich would respect the customized primary key.So, what is graphiti's opinion on the best place to define these customizations that reconciles our desire to expose the more "ideal/conventional" domain api while at the same time not setting ourselves up for a world of hurt with graphiti's resource associations and the frontend/mobile api clients (read: jsonapi spec libs). (Keeping in mind this is a legacy database so non-conventional PKeys, FKeys, and whatnot will be the rule, not the exception.)