GithubHelp home page GithubHelp logo

graphql-activerecord's People

Contributors

gustavovnicius avatar jongbeau avatar jorgechen avatar juice10 avatar mmahalwy avatar nater540 avatar tarebyte avatar theorygeek avatar vergenzt 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  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

graphql-activerecord's Issues

Add information about latest compatible graphql version

There is information, that adding compatibility with the latest version of graphql is in TODO, but there is no information about what is the latest version that is compatible. In gemspec there is information, that graphql should be < 2, is it correct? Will it work with 1.9.x?

GraphSupport.secure?

I am getting NameError (uninitialized constant GraphQL::Models::DefinitionHelpers::GraphSupport) when I use has_many_connection. I can't find any reference to GraphSupport anywhere on GitHub or Google that makes any sense as to what you're referencing. What does this call do and how does it work?

NoMethodError: undefined method `tasks' for nil:NilClass

I keep getting error:

"status": 500,
  "error": "Internal Server Error",
  "exception": "#<NoMethodError: undefined method `tasks' for nil:NilClass>",
  "traces": {
    "Application Trace": [
      {
        "id": 22,
        "trace": "app/controllers/graphql_controller.rb:9:in `execute'"
      }
    ],

Query:

Types::QueryType = GraphQL::ObjectType.define do
  name "Query"
  # Add root-level fields here.
  # They will be entry points for queries on your schema.

  field :tasks do
    type Types::TaskType
  end
end

Task:

Types::TaskType = GraphQL::ObjectType.define do
  name "Task"

  backed_by_model :task do
    attr :title
  end
end

Apollo client and model_from_id

Hi,

We are using graphql-activerecord for queries and it worked well for us. We are now trying to get mutations to work and got pretty close.

The only thing that is blocking us is the model_from_if callback. We are using Apollo client and client generated IDs.

Those IDs are uuid v4 but do not contain the model name like relay IDs does. Is there any other way we can get it in the model_from_id ?

Thanks !

Add support for type on has_one

Any chance we can add the "type" support to has_one association so it can support none strict association
I hacked the define_has_one to look like this

  reflection = model_type.reflect_on_association(association)

  fail ArgumentError.new("Association #{association} wasn't found on model #{model_type.name}") unless reflection
  fail ArgumentError.new("Cannot include #{reflection.macro} association #{association} on model #{model_type.name} with has_one") unless [:has_one, :belongs_to].include?(reflection.macro)

  # Define the field for the association itself

  camel_name = options[:name] || association.to_s.camelize(:lower)
  camel_name = camel_name.to_sym if camel_name.is_a?(String)

  type_lambda = options[:type] || resolve_has_one_type(reflection)

and it seems to work - should I PR it?

Remove manual association loading code

This gem has its own code for attempting to load an association. Right now, when it needs to load a set of associations, it goes through these steps:

  • It checks a cache of models that are stored on the query context. It does some relatively naive checks to see if a model that was already fetched from the database satisfies the association.
  • If it finds nothing in the cache, it then manually constructs a query, attempting to batch together multiple associations that need to be loaded.
  • Once it has gotten the results of that query, it then manually marks the association as loaded, saves any newly retrieved models to the cache, and returns the result.

While this approach works for probably the vast majority of associations, it has some drawbacks:

  • The manually constructed query is probably not cross-DBMS compatible. It relies heavily on usage of windowing functions to ensure that any scopes that apply ordering are preserved.
  • It ignores scopes that pass a SQL string to the where method, example: scope :active, -> { where("archived = 0 OR archived is null") }
  • And in general, it's basically just a rewrite of (complicated) code that already exists in ActiveRecord for loading associations.

A much better (and much simpler) approach would be to instead use ActiveRecord::Associations::Preloader, and just let Rails load the associations. This would also mean getting rid of the model caching that the gem does, which is probably better, since it's a bit of a hack anyway.

Error when declaring `GraphQL::Models.model_to_graphql_type`

Following the instructions in the README file and declaring the model_to_graphql_type proc will generate an error:

/config/initializers/graphql_activerecord.rb:23:in `<top (required)>': wrong number of arguments (given 1, expected 0) (ArgumentError)

I have it declared like so:

GraphQL::Models.model_to_graphql_type -> (model_class) { "Types::#{model_class.name}Type".safe_constantize }

Am I missing something extremely obvious? ๐Ÿ˜

Error after install gem

Hi

I have problem in my simple app
I just add gem 'graphql-activerecord' in Gemfile, install gems and I have this error

<module:Models>': uninitialized constant GraphQL::Batch (NameError)

Roadmap to 1.0

Hey everyone, I wanted to share the plans for this gem. I'm hoping to get to 1.0 within the next few months, which signifies it being really ready for general production use (even though GoCo is using this gem in production right now, as-is).

Here's my current TODO list for this gem:

  • Get a full test suite set up
  • Set up continuous integration
  • Add a demo app
  • Get some better-organized (and easier-to-digest) documentation
  • Try to find a better solution for association-load batching (this is for better cross-compatibility with DBMS's other than PostgreSQL)
  • Try to find a better solution for model_from_id, id_for_model, and gid (maybe)
  • Make model caching more controllable (or just eliminate it) (maybe)

Example end-to-end setup

It would be great to have an example end-to-end setup of usage so it's clear.

I've got something working roughly along the following lines, but I'm unsure if it's The Right Wayโ„ข.

# app/graphql/schema.rb
Schema = GraphQL::Schema.define do
  query QueryGraph
  max_depth 8
end

Schema.query_execution_strategy = GraphQL::Batch::ExecutionStrategy
Schema.mutation_execution_strategy = GraphQL::Batch::MutationExecutionStrategy
Schema.middleware << GraphQL::Models::Middleware.new
# app/graphql/query_graph.rb
QueryGraph = GraphQL::ObjectType.define do
  name "Query"
  description "The query root of this schema"

  field :employees, types[EmployeeGraph] do
    resolve -> (obj, args, ctx) { Employee.all }
  end
end
# In a controller, service or in the console
query_string = "{ employees { name } }"
result = Schema.execute(query_string, variables: query_variables)

Subsequently, it would be great if this gem could function as an Engine and just take care of the controller/route details for you, much like how ruby-graphiql does.

Happy to do a PR with a nudge in the right direction ๐Ÿ˜„

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.