Giter VIP home page Giter VIP logo

Comments (9)

amaierhofer avatar amaierhofer commented on July 4, 2024 1

You could query the schema for that i guess ..

[9] pry(main)> Graphiti::Schema.generate.fetch(:resources).collect { |r| r[:name] }
=> ["BugResource",
 "DepartmentResource",
 "EmployeeResource",
 "EpicResource",
 "FeatureResource",
 "MilestoneResource",
 "NoteResource",
 "PositionResource",
 "TaskResource",
 "TeamResource"]

from graphiti.

richmolj avatar richmolj commented on July 4, 2024 1

Maybe give Graphiti.resources a shot - should return the actual classes, though eager loading might still be an issue.

from graphiti.

Ben-Fenner avatar Ben-Fenner commented on July 4, 2024

Until I figure out something better, I'm introspecting the resources directory.
Here's that code if anyone else wants to use it:

    resource_location   = '/app/app/resources'
    resource_file_names = Dir.entries(resource_location).select{ |entity| File.file?(File.join(resource_location, entity)) && entity.ends_with?('_resource.rb') }
    resource_classes    = resource_file_names.map{ |file_name| file_name.chomp('.rb').camelize.constantize }
    resource_classes    = resource_classes.reject(&:abstract_class?)

I hope to soon be able to avoid this with something much simpler, but here I am for now.

from graphiti.

Ben-Fenner avatar Ben-Fenner commented on July 4, 2024

That's a bit more like what I was looking for. Thank you so much!

from graphiti.

Ben-Fenner avatar Ben-Fenner commented on July 4, 2024

Oh boy, crazily enough the Graphiti::Schema.generate technique above ultimately runs ::Rails.application.eager_load! which causes an application-wide class reload (I think) and when combined with the Rails development environment setting config.cache_classes = false causes an issue with the dry-events gem we're using (it throws a PublisherAlreadyRegisteredError error).

So while the technique above is great, I might have to go back to the directory introspection technique until I can figure out a solution for the dry-events problem. I'm discussing the issue on their support forum and will report back if I ever find a solution.

from graphiti.

Ben-Fenner avatar Ben-Fenner commented on July 4, 2024

Thank you for the suggestion. I'd actually already tried that after looking up the definition for the earlier suggestion:

def self.generate(resources = nil)

It seems the eager load is required, as running just Graphiti.resources returns an empty set if the eager loading is not performed first. Well, that's the case in the Rails console, let me check the test environment...

Hmmm, it seems to work in testing. So maybe I'll roll with Graphiti.resources.reject(&:abstract_class?) for now and see how that goes. Thanks for making me re-check. 👍

from graphiti.

Ben-Fenner avatar Ben-Fenner commented on July 4, 2024

Well, it worked in the test environment, but not in development*. The eager loading seems to be required there.

So I'm back to introspecting the file system until I can hunt down a solution for the dry-events problem. I'd link to that discussion but my post over there hasn't been approved yet (it's been over 24 hours now). 😞

*Edit: Ha! I got things working in development by adding the app/resources path to the config.autoload_paths setting in my applicatoin.rb file. So I think I'm back in business with the Graphiti.resources technique!

Edit 2: Ugh. After some time the Graphiti.resources solution went back to returning an empty set in development even though I am auto-loading the resource directory. It seems I just can't win. I'm going to have to go back to the file system introspection.

Edit 3: It seems the auto loading only requires the files when they are needed, and they are not needed early enough in my code to produce desired results. I looked into manually requiring all of the resources beforehand but this causes them to be loaded twice, with warnings about constants being already declared. So I looked into conditionally requiring them if they weren't already, but I did not find a good way of accomplishing that. Ultimately it all comes back to needing to look at the file system anyway, so I'm going to stick with my initial file system introspection shown in the second post above.

from graphiti.

Ben-Fenner avatar Ben-Fenner commented on July 4, 2024

I'll reply with a link to the dry-events discussion when I get it, but really this issue is solved from a Graphiti point of view. There are decent techniques listed above for getting a list of all resource names using built-in Graphiti classes/methods.
(Then there is the file system introspection technique.)

So I consider this issue closed. Cheers and thanks! 😁

from graphiti.

Ben-Fenner avatar Ben-Fenner commented on July 4, 2024

And finally, here is the link to the dry-events issue and discussion: https://discourse.dry-rb.org/t/publisher-already-registered-error-in-dry-events-when-reloading-classes/1473

from graphiti.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.