You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have routes mapped to namespaced controllers (Api::V1::NotesController) much like the one below:
Attempted solution:
Create new rails app: rails new sample-graphiti-api --api -m https://www.graphiti.dev/template
Press <ENTER> if asked for the namespace (default is /api/v1)
rails generate model Note content:string
rails generate graphiti:resource note content:string created_at:datetime (rails generate graphiti:resource api/v1/note content:string created_at:datetime doesn't work so we do it manually)
Move app/resources/note_resource.rb to app/resources/api/v1/note_resource.rb and change NoteResource to Api::V1::NoteResource
Move app/controllers/notes_controller.rb to app/controllers/api/v1/note_resource.rb and change NotesController to Api::V1::NotesController. Also, change all occurrences of NoteResource to Api::V1::NoteResource. File should look like this:
Graphiti::Errors::InvalidEndpoint ( Api::V1::NoteResource cannot be called directly from endpoint /api/v1/notes#index!
Either set a primary endpoint for this resource:
primary_endpoint '/my/url', [:index, :show, :create]
Or whitelist a secondary endpoint:
secondary_endpoint '/my_url', [:index, :update]
The current endpoints allowed for this resource are: [{:path=>:"/api/v1/notes", :full_path=>:"/api/v1/api/v1/notes", :url=>:"http://localhost:3000/api/v1/api/v1/notes", :actions=>[:index, :show, :create, :update, :destroy]}]
):
The text was updated successfully, but these errors were encountered:
I used the same workaround ! But i did self.endpoint_namespace = '' in ApplicationRessource that inherit from Graphiti::Resource. Then, all my resource inherit from ApplicationResource so i don't need to override endpoint_namespace in every resources.
Also, you don't need to override self.model in every resource. In ApplicationResource again, override the infer_model method with something like this:
What I hope to achieve
Have routes mapped to namespaced controllers (
Api::V1::NotesController
) much like the one below:Attempted solution:
rails new sample-graphiti-api --api -m https://www.graphiti.dev/template
<ENTER>
if asked for the namespace (default is/api/v1
)rails generate model Note content:string
rails generate graphiti:resource note content:string created_at:datetime
(rails generate graphiti:resource api/v1/note content:string created_at:datetime
doesn't work so we do it manually)app/resources/note_resource.rb
toapp/resources/api/v1/note_resource.rb
and changeNoteResource
toApi::V1::NoteResource
app/controllers/notes_controller.rb
toapp/controllers/api/v1/note_resource.rb
and changeNotesController
toApi::V1::NotesController
. Also, change all occurrences ofNoteResource
toApi::V1::NoteResource
. File should look like this:GET /api/v1/notes
. An error occurs:The text was updated successfully, but these errors were encountered: