Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymorphic associations and GraphQL UnionType in query #8

Open
geneeblack opened this issue Nov 16, 2017 · 0 comments
Open

Polymorphic associations and GraphQL UnionType in query #8

geneeblack opened this issue Nov 16, 2017 · 0 comments

Comments

@geneeblack
Copy link

geneeblack commented Nov 16, 2017

First off, great job. I struggled in my own code traversing the ast_node to determine the include/preload models to use in the resultant query. What you've done has made my life much easier.

I ran into an issue when using a UnionType to express a polymorphic association and then attempting to traverse the ast_node to build the references. The issue is that the UnionType is expressing a polymorphic association. The polymorphic association does not have a direct class reference. So in the following line an empty result is returned and the code errs on the next line.

https://github.com/nettofarah/graphql-query-resolver/blob/master/lib/graphql/query_resolver.rb#L66

I don't think there is a way to 'fix' this since the only way that I know of to determine the models that a polymorphic association references is to do a table scan. I am simply punting at this point by checking if !selection_name.nil? and hitting next if it is. Maybe you can solve this in another way. It's not a high priority for me at this point since we only use polymorphic associations in two cases in our app.

selection_name = class_name.reflections.with_indifferent_access[selection.name].options[:class_name]
begin   
    current_class_name = selection_name.singularize.classify.constantize
    dependencies[selection.name.to_sym] = get_implied_includes(current_class_name, selection)
rescue
    Rails.logger "polymorphic associations do not have a resolvable class_name"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant