Skip to content

ObjectCache: how to handle child objects without their own id? #5110

Answered by rmosolgo
ludo asked this question in Q&A
Discussion options

You must be logged in to vote

Hey, thanks for the great question.

Yes, I think cache_dependencies_for is the way to go, you could implement it like this:

class Types::FormFieldType < Types::BaseObject
  def self.cache_dependencies_for(form_field, context)
    form_field.parent 
  end  
  
  # ... 
end 

Can you return the form field's form object easily? The most fail-safe would be to use an application-defined method on the form field (or add one if necessary, add "form" => form to the hash, etc). That way, you could be sure that the form field would have access to the right parent, no matter what.

In a pinch, you could use GraphQL-Ruby's "scoped context" field to accomplish this, but I don't recommend it because scop…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ludo
Comment options

Answer selected by ludo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants