Comments (9)
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.
Maybe give Graphiti.resources
a shot - should return the actual classes, though eager loading might still be an issue.
from graphiti.
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.
That's a bit more like what I was looking for. Thank you so much!
from graphiti.
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.
Thank you for the suggestion. I'd actually already tried that after looking up the definition for the earlier suggestion:
graphiti/lib/graphiti/schema.rb
Line 5 in 22808b8
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.
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.
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.
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)
- Sideposts fail when associating has_many resource with the `as:` option
- Filtering / Sorting a Parent Resource based off its associations value HOT 1
- Ruby-3.0 splits named and positional parameters
- sideposting - associating same newly created record with multiple records that are also being created
- Sideposting- includes don't show when test with Postman
- Polymorphic has_one and has_many doesn't respect custom polymorphic_name
- Data access questions HOT 1
- Missing next page link when the resource is a postgres table has json columns HOT 1
- Proposal to allow for overriding relationship getter HOT 1
- Record ID for authorization
- Guide - Outdated external link
- can not call method with args including keyword inside attribute/extra_attribute
- Problem in namespacing controllers HOT 2
- Template for tutorials are broken
- Parsing filter values with {{}} has unwanted side effects.
- Resources with circular relationships fail to load
- Can not call method with key args inside extra_attribute/attribute block HOT 3
- my_resource.data raises Graphiti::Errors::RecordNotFound in #create action after Graphiti::Resource#build(params) when the table is empty HOT 5
- Deep Query Filter HOT 1
- Not compatible with Rails 7.1 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from graphiti.