basicbrogrammer / hai Goto Github PK
View Code? Open in Web Editor NEWA Ruby gem inspired by ash-elixir that builds A CRUD api based on ActiveRecord models.
License: MIT License
A Ruby gem inspired by ash-elixir that builds A CRUD api based on ActiveRecord models.
License: MIT License
Currently, no arguments are required in a model's graphql schema. This is fine, because validation can be added to the model file which would prevent an instance of that model from being created with invalid attributes.
It would be nice however if we could parse the validations on a model and set the required attribute on the GQL argument to be required if a presence
validation is found
There seems to be an issue when attempting to create an object through a mutation when the model was created with only the default attributes given to a model in Rails (id
, created_at
, updated_at
).
This seems to happen because we are early returning when cycling through the model attributes when it encounters the above attributes. However if the model only has these, the attr
variable becomes []
and we receive the below error
hai/lib/hai/graphql/create_mutations.rb
Lines 16 to 33 in 6379657
Below is the mutation along with the stack trace
mutation {
createTask(input: {}) {
result {
id
}
}
}
{
"errors": [
{
"message": "wrong number of arguments (given 0, expected 1)",
"backtrace": [
"/usr/local/rvm/gems/ruby-3.1.3/gems/hai-0.0.4/lib/hai/graphql/create_mutations.rb:29:in `block in define_resolver'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/resolver.rb:107:in `public_send'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/resolver.rb:107:in `block (3 levels) in resolve_with_support'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema.rb:1056:in `after_lazy'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/resolver.rb:93:in `block (2 levels) in resolve_with_support'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema.rb:1056:in `after_lazy'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/resolver.rb:84:in `block in resolve_with_support'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema.rb:1056:in `after_lazy'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/resolver.rb:73:in `resolve_with_support'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/relay_classic_mutation.rb:60:in `resolve_with_support'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/field.rb:686:in `public_send'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/field.rb:686:in `block (2 levels) in resolve'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/field.rb:807:in `with_extensions'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/field.rb:657:in `block in resolve'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema.rb:1056:in `after_lazy'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/field.rb:655:in `resolve'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/execution/interpreter/runtime.rb:511:in `block (3 levels) in evaluate_selection_with_args'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/tracing.rb:65:in `trace'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/execution/interpreter/runtime.rb:510:in `block (2 levels) in evaluate_selection_with_args'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/execution/interpreter/runtime.rb:842:in `call_method_on_directives'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/execution/interpreter/runtime.rb:507:in `block in evaluate_selection_with_args'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/execution/interpreter/runtime.rb:942:in `after_lazy'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/execution/interpreter/runtime.rb:445:in `evaluate_selection_with_args'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/execution/interpreter/runtime.rb:438:in `block in evaluate_selection'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/schema/member/has_arguments.rb:246:in `block (3 levels) in coerce_arguments'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/dataloader.rb:181:in `block in run'",
"/usr/local/rvm/gems/ruby-3.1.3/gems/graphql-2.0.16/lib/graphql/dataloader.rb:306:in `block in spawn_fiber'"
]
}
],
"data": {}
}
Currently all models are exposed through the REST API with no easy way of restricting what is visible. We should look into a way that allows user's to identify what models they don't want to expose.
This can also potentially be tackled by doing the inverse. Perhaps we flip things around and every model is restricted by default. We would then need some way to identify what models we want to expose.
The graphql api has more fine grained control over what is exposed.
In app/graphql/types/mutation_type.rb
we can control what models can be created/updated through a mutation by adding the name of the model to the method call. ex. hai_muation(Task, User, ...)
. The same can be done for querying by modifying what models are passed to hai_query(Task, User, ...)
When using the installation script, all models are included in these lists
create an install script to add boilerplate includes
Currently only the db column methods are exposed. We want the ability to add a method on a model and expose that to the api.
This will need to be strongly typed as well.
You may not want to expose all attributes from your model. We need a way to hide some attributes from the api.
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.