by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Heinrich Klobuczek
@klobuczek
Since this is not in activerecord I doubt this will ever be documented
Mark Fruhling
@mfruhling

I'm new to neo4j and trying to setup a rails 6.0.2.2 app on ruby 2.7.1. I've followed the setup instructions but I'm getting a 404 response code. I have successfully connected to my neo4j database through a simple ruby script, so I do know the database if functioning properly. Any help in troubleshooting what is going on with my rails app would be greatly appreciated. I must be missing something obvious or misreading the setup instructions.

ETHON: Libcurl initialized
ETHON: performed EASY effective_url=http://localhost:7474/db/data/schema/constraint response_code=404 return_code=ok total_time=0.010523
 HTTP REQUEST: 15ms GET http://localhost:7474/db/data/schema/constraint (0 bytes)

Here is my application.rb

require_relative 'boot'

require 'rails/all'
require 'neo4j/railtie'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Gg
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 6.0

    config.neo4j.session.type = :http
    config.neo4j.session.url = 'http://neo4j:redacted@localhost:7474'

    # After 8.0.x of `neo4j` gem
    # Switched to allowing a "configurator" since everything can be done there
    config.neo4j.session.options = {
      faraday_configurator: proc do |faraday|
        # The default configurator uses typhoeus (it was `Faraday::Adapter::NetHttpPersistent` for `neo4j-core` < 7.1.0), so if you override the configurator you must specify this
        faraday.adapter :typhoeus
        # Optionally you can instead specify another adaptor
        # faraday.use Faraday::Adapter::NetHttpPersistent

        # If you need to set options which would normally be the second argument of `Faraday.new`, you can do the following:
        faraday.options[:open_timeout] = 5
        faraday.options[:timeout] = 65
        # faraday.options[:ssl] = { verify: true }
      end
    }

    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.

  end
end

Here is the ruby script that successfully connects and fetches the few nodes that I created through Cypher

require 'neo4j-core'
require 'neo4j/core/cypher_session/adaptors/http'
require 'neo4j/core/cypher_session/adaptors/bolt'
require 'net/http'

session = Neo4j::Core::CypherSession.new(Neo4j::Core::CypherSession::Adaptors::HTTP.new('http://neo4j:redacted@localhost:7474'))

results = session.query("match (n) return n")

results.each do |row|
  puts row
end
Steven Deobald
@deobald
@mfruhling I'm also pretty new to Neo4j and, coincidentally, on the same versions of Rails and Ruby you are. But I'm pretty convinced I prefer bolt to http. If you want an example of that setup with bolt, you can look at the config for our app: https://github.com/pariyatti/kosa
Subin Sapkota
@SubinSapkota_twitter
Trying to setup Factories using FactoryBot for ActiveNodes. Is there documentation around defining a has_many :in relationship? I'm getting an undefined method relationship_type error when trying to just create an association.
Heinrich Klobuczek
@klobuczek
??? Please paste some code.
Subin Sapkota
@SubinSapkota_twitter
Here's an example from a User-[ReactedWith]->Reaction-[ReactedTo]->Post` model
FactoryBot.define do
  factory :reaction do
    name { "Happy" }
    association :user, factory: :user
    post { FactoryBot.create(:post) }
  end
end
Heinrich Klobuczek
@klobuczek
and the has_many declaration?
Subin Sapkota
@SubinSapkota_twitter
It's same for has_many or has_one. May be doing something wrong as this is my first time trying out the gem. This is my definition for the node:
 class Reaction
  include Neo4j::ActiveNode
  has_one :in, :user, origin: :post_reactions
  has_one :out, :post, type: :REACTED_TO, model_class: :Post
end

For :in relationships I'm getting an error of

 NoMethodError:
       undefined method `relationship_type' for nil:NilClass
`

Removing :user association from the factory works fine.

Heinrich Klobuczek
@klobuczek
Could you paste the associations on User?
Subin Sapkota
@SubinSapkota_twitter
That was it! Sorry for wasting your time. I had the wrong origin: defined on Reaction. It works great now.
Thank you for your help.
Heinrich Klobuczek
@klobuczek
Np, it was an easy one for a change.
Mark Fruhling
@mfruhling
Thank you for sharing your setup @deobald . I changed my configuration to use bolt and am now getting a different error message.
RuntimeError (Couldn't agree on a version (Sent versions [1, 0, 0, 0])):

neo4j-core (9.0.0) lib/neo4j/core/cypher_session/adaptors/bolt.rb:134:in `handshake'
neo4j-core (9.0.0) lib/neo4j/core/cypher_session/adaptors/bolt.rb:37:in `connect'
neo4j-core (9.0.0) lib/neo4j/core/cypher_session.rb:14:in `initialize'
neo4j (9.6.2) lib/neo4j/session_manager.rb:13:in `new'
neo4j (9.6.2) lib/neo4j/session_manager.rb:13:in `open_neo4j_session'
neo4j (9.6.2) lib/neo4j/railtie.rb:68:in `setup!'
neo4j (9.6.2) lib/neo4j/railtie.rb:52:in `block (2 levels) in <class:Railtie>'
neo4j (9.6.2) lib/neo4j/active_base.rb:18:in `establish_session'
neo4j (9.6.2) lib/neo4j/active_base.rb:8:in `current_session'
neo4j (9.6.2) lib/neo4j/shared.rb:17:in `neo4j_session'
neo4j (9.6.2) lib/neo4j/active_node/labels.rb:144:in `mapped_label'
neo4j (9.6.2) lib/neo4j/migrations/runner.rb:16:in `initialize'
neo4j (9.6.2) lib/neo4j/migrations.rb:15:in `new'
neo4j (9.6.2) lib/neo4j/migrations.rb:15:in `check_for_pending_migrations!'
neo4j (9.6.2) lib/neo4j/migrations/check_pending.rb:13:in `call'
Steven Deobald
@deobald
Oh man. I've seen this before... but I can't remember why. I think that might be a TLS error?
Heinrich Klobuczek
@klobuczek
@deobald are you using the old bolt adapter or neo4j-ruby-driver?
Steven Deobald
@deobald
@klobuczek The old bolt adapter. I'm still on 9.6
Mark Fruhling
@mfruhling
@deobald your application has ssl => false, so I assumed this wouldn't be a TLS error
config.neo4j.session.options = {ssl: false}
Steven Deobald
@deobald

@mfruhling Ah. I wasn't sure if you'd configured SSL or not. I have a couple other settings changed in my neo4j config for development:

dbms.security.auth_enabled=false
dbms.connector.bolt.enabled=true
#dbms.connector.bolt.tls_level=OPTIONAL
dbms.connector.bolt.listen_address=:7006

I came to the conclusion that getting off the default ports almost always makes sense on the dev box because I would keep accidentally trying to connect to a default instance that wasn't configured.

Steven Deobald
@deobald
I'm really having a hard time understanding Query Clause Methods... I'm not sure if I'm just overtired or the documentation is particularly confusing.
I'd really like to do this:
Card.where(published: true).order('updated_at DESC')
Steven Deobald
@deobald

It doesn't seem like that's possible from the methods available on a model object (I'd love to know that it is, somehow). So I'm trying the Core::Query object:

Neo4j::ActiveBase.current_session.query.match(c: :Card).order('c.updated_at DESC')

...complains that query isn't receiving any arguments, so I'm not sure how to actually use the Core Query Methods on it?

    raw_monkey_query = "match (c:Card) where c.published = true return c order by c.updated_at DESC"
    cards = Neo4j::ActiveBase.current_session.query(raw_monkey_query)

...this works but it returns some object that's so far removed from my Rails models I might as well just go back to py2neo. ;)

Any thoughts?

fwiw, this worked perfectly:

Card.where(published: true).order(:updated_at)

...but because the QueryProxy object doesn't have a reverse method, that's insufficient.

Steven Deobald
@deobald
Oh god.
There's a #to_a method. :grimacing: ...should have thought of that. This is super inefficient, though. I'd love to know the right way to do this.
Steven Deobald
@deobald
Next question: Does, uh, no one actually serialize their Neo4j models to JSON? I can't find an easy way to include associated nodes in to_json on a model.
Steven Deobald
@deobald
Ugh. So, the last issue I can find recommends the gem representative_view ... which would be fine, if it supported a version of Rails newer than 3.x. It... doesn't look like there's a clean way to generate JSON from ActiveNode models?
Steven Deobald
@deobald
Whoa, sorry. It looks like include: actually does work? Not sure what I did wrong the first time. Now I'm just curious what the equivalent of calling super in an ActiveRecord model would be, if I want to override as_json
Steven Deobald
@deobald
Okay, finally dug through the source. Sorry for the noise... I didn't realize that neo4j.rb was handing all the JSON responsibilities over to ActiveModel.
Mark Fruhling
@mfruhling
Trying different ports, but with the same results. I'm using the neo4j Desktop for my setup. Is there somewhere in the Desktop app that I can see if my bolt or http requests are making it to the database that I have created?
Mark Fruhling
@mfruhling

I was able to get a neo4j & Rails 6 app up and running, but not sure I identified the root cause of the 404. Some things I learned...
1) The Typhoeus library had a commit that I don't believe is reflected in the 1.3.1 gem. Causing the error below.

NameError (uninitialized constant Faraday::Error::ConnectionFailed
Did you mean?  Faraday::ConnectionFailed):

Installing that gem from github resolved that.

gem 'typhoeus', git: 'https://github.com/typhoeus/typhoeus'

2) I totally missed installing the rake-tasks when reading the docs. They allowed me to install a neo4j instance directly in my db/neo4j/development folder. I changed the port and got connected.

gem 'neo4j-rake_tasks'

3) I got an error saying that neo4j needed JVM 1.8, so I needed to install the JDK ver. 8 and switch my system to point to the older version.
4) Deleted the Neo4j Desktop App completely. Not sure why that setup didn't work for me originally.
Hope that info helps someone in the future.

Mark Fruhling
@mfruhling
Is there somewhere I can reference a list of neo4j.session options? I'm deploying my rails app to Heroku and have Environment variable that hold the bolt_url, username, and pwd. Are there separate config keys for those three, or do I need to stitch everything together in the URL param?
Ilgiz Mustafin
@imustafin

Hi. How to register Typecasters in Rails 6 development mode?

I define a typecaster class, do include Neo4j::Shared::Typecaster in it. When it is eager-loaded in production, it gets registered because of the include, but in development there is no eager-loading, so the typecaster is not registered I can't typecast attributes of this type.

Steven Deobald
@deobald
@mfruhling I'm not sure if you mean the session path URL? If it's any help, I just do something like this: https://github.com/pariyatti/kosa/blob/505364334a29338c58f3d1ad97c0300f7170b4ee/config/environments/production.rb#L112
@imustafin If an example is of any help to you, this is what Amit suggested I do in my codebase: https://github.com/pariyatti/kosa/tree/505364334a29338c58f3d1ad97c0300f7170b4ee/app/helpers/neo4j ...these get loaded for me in all environments.

FYI: I'm finding a surprising number of gems depend directly on ActiveRecord (I don't remember that being the case a decade ago when I last used Rails...) so I've been on the hunt for smaller, simpler gems. Clearance has been a godsend but I needed to tweak two lines in it to get it working with ActiveGraph. If anyone wants to thumbs-up this PR, maybe they'll take it? ;)

thoughtbot/clearance#894

Ilgiz Mustafin
@imustafin

@deobald thanks for your response. When I had only one converter, I would just load it in the model class of the type like this:

class MySpecialModel
  MySpecialModelConverter
  ...
end

Now that I have several type converters, I decided to preload them manually in config/application.rb like this:

    config.after_initialize do
      Rails.root.glob('app/neo4j_converters/*.rb').each do |f|
        f.to_s[%r{.*/(.*).rb}, 1].camelize.constantize
      end
    end

It seems to work like this. However, I still believe that there is a better way...

Wojciech Maciejak
@wmaciejak

Hi guys! I have some issues during development application with Neo4j on board. I've tried to debug gem and find anything useful but I'm not sure if I didn't get too deep. Wanted to clarify some things.

We have action - let's name it create:

Neo4j::ActiveBase.run_transaction do |tx|
  major_logic # inside is standard ActiveNode usage

  minor_logic # inside is a few additional raw cypher queries wrapped in one transaction so it will be kinda:
  # Neo4j::ActiveBase.run_transaction do |tx|
  #   Neo4j::ActiveBase.current_session.query("something")
  #   Neo4j::ActiveBase.current_session.query("other_things")
  # end
end

Code works fine until it comes to the minor_logic part where happens something like this:

Neo4j::ActiveBase.run_transaction do |tx|
  major_logic # works fine

  minor_logic 
  # Neo4j::ActiveBase.run_transaction do |tx|
  #   Neo4j::ActiveBase.current_session.query("something") -> works fine
  #   Neo4j::ActiveBase.current_session.query("other_things") -> raising `Neo4j::Core::CypherSession::CypherError: Neo.ClientError.Transaction.TransactionNotFound`
  # end
end

I don't have any idea why this happening and if there are some issues with transactions for current_session.query usage.

Anyone have some ideas?

Joram Ngwenya
@joramn
I am trying to implement JWT on Neo4jrb, what would be the equivalent of ActiveRecord::RecordNotFound in Neo4jrb?
Gareth Bradley
@garethbradley

I am trying to implement JWT on Neo4jrb, what would be the equivalent of ActiveRecord::RecordNotFound in Neo4jrb?

Not familiar with JWT, but I use something like this...raise Neo4j::RecordNotFound if @customer.blank?

Has anyone got experience of shrine for document uploads to AWS S3? Tried using CarrierWave which happily saves the doc to S3 in the cache folder, but upon the record saving, it won't then save it to the proper location. So, given up on CarrierWave and looking for an alternative. Shrine looks promising - or any other suggestions? Cheers
Amit Suryavanshi
@amitTheSongadya_twitter
@garethbradley There is a PR open to get carrierwave-neo4j working, soon we will have release of it.
Ilan Berci
@iberci

Problem: 404s when calling ActiveNode class methods

Environment: From within a rails 6 app calling out to a non embedded local neo4j server
Neo4j server 4.04, Neo4j 9.6.2/ Neorj-Core 9.0.0

My connection/config works since I can do the following with expected results: MyEvent.new.class.neo4j_session.query("match (n) return n")

But if I do MyEvent.all()

===============================================
HTTP REQUEST: 3ms GET http://localhost:7474/db/data/schema/constraint (0 bytes)
Traceback (most recent call last):
Neo4j::Core::CypherSession::ConnectionFailedError (Connection failure: )
status: 404

============================================================

Sure enough, when I curl those urls, I am getting 404’s against that so it appears that I am not calling with invalid apis?

I get this behavior with both bolt and http connection.

Any assistance would be greatly appreciated

Ohh.. and I also wanted to pass of my thanks on such a wonderful library.. Thank you kindly.
Heinrich Klobuczek
@klobuczek
neo4j gem 9.6.x in not compatible with neo4j server 4.0.x
activegraph gem 10.0.0-beta is
Ilan Berci
@iberci
thank you
Ilan Berci
@iberci
The docs on the ActiveGraph repo reference the old neo4j docs from my understanding. Is there any sample configs for ActiveGraph usage that you can refer me to.
Heinrich Klobuczek
@klobuczek
I know. I feel bad about it. That’s the only thing holding us back from releasing 10.0.0. This is pretty much what changed:
  config.neo4j.driver.url = 'neo4j://localhost:7687'
  config.neo4j.driver.auth_token = Neo4j::Driver::AuthTokens.basic('architect', 'password')
  config.neo4j.driver.config.encryption = false
Emil Kampp
@ekampp

Good morning. Can someone recommend a good way to integrate something like NewRelic (or another APM) that integrates well with ActiveGraph?

Currently, in NewRelic ActiveGraph time is shown as controller time. That makes it very hard to understand what's going on.