Git Product home page Git Product logo

graphql-query-resolver's People

Contributors

khamusa avatar nettofarah avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql-query-resolver's Issues

Passing context to Resolver

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!

Note: when using connections with a (first:n) directive to resolve relations

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.

Polymorphic associations and GraphQL UnionType in query

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.