An adapter to make Graphiti work with the ActiveGraph(former Neo4jrb) OGM. This gem allows you to easily build jsonapi.org compatible APIs for GraphDB using Graphiti and ActiveGraph.
Add this line to your application's Gemfile
:
gem 'graphiti-activegraph'
And then execute:
bundle install
Or install it yourself as:
gem install graphiti-activegraph
While defining a Resource class, inherit it from Graphiti::ActiveGraph::Resource
class PlanetResource < Graphiti::ActiveGraph::Resource
For model backed by ApplicationRelationship
instead of ApplicationNode
, we have to set relationship_resource
to true
while defining resource class.
class RelationshipBackedResource < Graphiti::ActiveGraph::Resource
self.relationship_resource = true
end
-
Efficient Sideloading: Unlike Graphiti, which executes multiple queries for sideloading, graphiti-activegraph leverages
with_ordered_associations
from ActiveGraph to fetch sideloaded data in a single query, improving performance. -
Sideposting Behavior: graphiti-activegraph allows assigning and unassigning relationships via sideposting but does not support modifying a resource’s attributes through sideposting.
-
Thread Context Handling: Graphiti stores context using
Thread.current[]
, which does not persist across different fibers within the same thread. In graphiti-activegraph, when running on MRI (non-JRuby environments), the gem usesthread_variable_get
andthread_variable_set
. Ensuring the context remains consistent across different fibers in the same thread.
graphiti-activegraph introduces two new methods on the Graphiti resource class:
with_preloaded_obj(record, params)
– Renders a single preloaded ActiveGraph object without querying the database.
all_with_preloaded(records, params)
– Renders multiple preloaded ActiveGraph objects without additional queries.
Note: These methods assume that the provided records are final and will not apply Graphiti’s filtering, sorting, or scoping logic.
Bug reports and pull requests are welcome on GitHub at https://github.com/mrhardikjoshi/graphiti-activegraph. This project is intended to be a safe, welcoming space for collaboration.
- Make sure version file is updated/incremented in master branch
- git checkout master
- git pull origin master
- git tag v1.2.3
- git push origin v1.2.3
- gem build graphiti-activegraph.gemspec
- gem push graphiti-activegraph-1.2.3.gem
The gem is available as open-source under the terms of the MIT License.