goco-inc / graphql-activerecord Goto Github PK
View Code? Open in Web Editor NEWLicense: MIT License
License: MIT License
Looks interesting, have any documentation?
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?
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?
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
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 !
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?
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:
While this approach works for probably the vast majority of associations, it has some drawbacks:
scope :active, -> { where("archived = 0 OR archived is null") }
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.
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? ๐
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)
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:
model_from_id
, id_for_model
, and gid
(maybe)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 ๐
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.