Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
graphql-rails-activereflection
Advanced tools
Reflection over GraphQL for ActiveRecord models and validators
The purpose of this gem is to enable ActiveRecord reflections on models over GraphQL.
At release, this gem only contains reflections on validators. This is to avoid duplication and doubling up on the front-end for how to validate form inputs.
Eventually I would like to include some React examples and sample container components to apply the validators.
To begin, install the gem by adding it to the Gemfile
:
gem 'graphql-rails-activereflection'
You're now ready to expose validators for your GraphQL Fields. This only works for fields that resolve to ActiveRecord Models.
To expose a field, add the following line:
implements GraphQL::Rails::ActiveReflection::Model.interface, inherit: true
And that's it! This will add a _model
field to the object type and enables the following query:
fragment on YourObjectType {
_model: ActiveReflectionModel {
attributes: [ActiveReflectionAttribute] {
name: String
field_name: String
validators: [ActiveReflectionValidator] {
absence: Boolean
presence: Boolean
uniqueness: Boolean
with_format: String
without_format: String
min_length: Integer
max_length: Integer
inclusion: [String]
exclusion: [String]
}
validate(int: Integer, str: String, float: Float, bool: Boolean): ActiveReflectionValidation {
valid: Boolean
errors: [String]
}
}
}
}
The _model
field will resolve to whatever type Schema.resolve_type
returns for that object.
Only the fields on that type will be exposed as attributes
- where name
is the attribute name and field_name
is the field name that exposed the attribute.
Each of the validators corresponds to the standard Rails validators. Almost all validators for an attribute will be returned, except those that have the if
or unless
conditionals. This is by design and therefore make note that any conditional validations will have to be performed manually.
There is also the validate(...)
field with arguments for standard scalar types. Any one of the arguments can be provided, but only one. The result will contain a valid
boolean and a list of errors
strings returned from the validators.
In the future all of the validate(...)
should be chained for a single call.
Future plans for this module are to expose any reflections for an ActiveRecord model.
If you wish to contribute to this project, any pull request is warmly welcomed.
validate(...)
callsFAQs
Unknown package
We found that graphql-rails-activereflection demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.