nettofarah / graphql-query-resolver Goto Github PK
View Code? Open in Web Editor NEWMinimize N+1 queries generated by GraphQL and ActiveRecord
License: MIT License
Minimize N+1 queries generated by GraphQL and ActiveRecord
License: MIT License
It seems the return type parameter is unused. Shall we deprecate it on next releases with a warning?
I would love to try your gem but its runtime dependency on graphql
is pessimistically restricted at ~> 1.0.0
.
Any chance it can be a little more optimistic?
https://github.com/nettofarah/graphql-query-resolver/blob/master/graphql-query-resolver.gemspec#L22
My graphql controller determines the current user and stores it in ctx[:current_user]
. I use that to scope the returned records.
field :Biometrics, !types[Types::BiometricType] do
resolve -> (obj, args, ctx) {
ctx[:current_user].biometrics
}
end
However, I'm trying to use the fancy query resolver. What's the best practice to limiting the scope to the current_user. And how do I access ctx[:current_user]
in my resolver class? scope { ctx[:current_user].biometrics }
doesn't work as it doesn't seem to have access to ctx
Cheers Team!
when using graphql connections to resolve relations and a limit is specified on the connection, n+1 queries are still employed on the relation even though the primary query successfully batches the query.
given the following query:
query {
log {
items {
edges {
node {
files {
edges {
node {
id
}
}
}
}
}
}
}
}
the preloads limit the result query to 1 query
but if specifying a limit (explicitly or default using GraphQL schema setting default_max_page_size)
query {
log {
items {
edges {
node {
files(first:2) {
edges {
node {
id
}
}
}
}
}
}
}
}
the batch is successfully done to build the initial log items with its associated files, but then n+1 queries are done to the files applying the limit specified. I'm not sure if there is any way to prevent this since it appears it is being generated from GraphQL-ruby
SELECT
`log`.`id` AS t0_r0,
FROM
`log`
LEFT OUTER JOIN
`files` ON `log`.`id` = `files`.`log_id`
WHERE
`log`.`id` IN (230811);
File Load (0.4ms) SELECT `files`.* FROM `files` WHERE `files`.`log_id` = 230811 LIMIT 2
I just wanted to let you know if you weren't already aware.
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
The link to graphql-ruby in the README has a typo, it should be https://github.com/rmosolgo/graphql-ruby.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.