graphiti-api / graphiti

Stylish Graph APIs
https://www.graphiti.dev/
MIT License
960 stars 138 forks source link

Graphiti::Errors::InvalidLink #425

Closed AlexeyMatskevich closed 2 years ago

AlexeyMatskevich commented 2 years ago

Hello, I'm trying to use Graphiti.

I'm stuck with this error.

Failure/Error: render jsonapi: user, status: 201

      Graphiti::Errors::InvalidLink:
        UserResource: Cannot link to sideload :cards!

        Make sure the endpoint "/api/v1/cards" exists with action :index, or customize the endpoint for CardResource.

        If you do not wish to generate a link, pass link: false or set self.autolink = false.

My models:

class User < ApplicationRecord
  has_many :cards

  validates :email, uniqueness: true
end

class Card < ApplicationRecord
  belongs_to :user
end

My resources:

class ApplicationResource < Graphiti::Resource
  self.abstract_class = true
  self.adapter = Graphiti::Adapters::ActiveRecord
  self.base_url = Rails.application.routes.default_url_options[:host]
  self.endpoint_namespace = '/api/v1'
end

class UserResource < ApplicationResource
  attribute :email, :string

  has_many :cards
end

class CardResource < ApplicationResource
  attribute :bonuses, :integer

  belongs_to :user
end

My routes.rb:

Rails.application.routes.draw do
  scope path: ApplicationResource.endpoint_namespace do
    resources :users, only: %i[show create update index]
    resources :cards, only: %i[show index]
  end
end

So action :index exists. What else do I need to do to fix this error?

AlexeyMatskevich commented 2 years ago

I trivially had one typo in the controller file name