Skip to content

Instantly share code, notes, and snippets.

@apauly
Created August 17, 2020 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apauly/f44886f9abd86a818d23090988a8e861 to your computer and use it in GitHub Desktop.
Save apauly/f44886f9abd86a818d23090988a8e861 to your computer and use it in GitHub Desktop.
Graphiti requires writable id also for relations
require 'graphiti'
class User; end
class Post; end
class UserResource < Graphiti::Resource
attribute :id, :integer_id, writable: false
has_many :posts
end
class PostResource < Graphiti::Resource
attribute :id, :integer_id, writable: false
attribute :title, :string, writable: true
belongs_to :user
end
params = {
data: {
id: 123,
type: 'posts',
relationships: {
user: {
data: { id: 12, type: 'users' }
}
}
}
}
begin
resource = PostResource.find(params)
rescue Graphiti::Errors::InvalidRequest => e
puts e.message
end
# There were one or more errors with your request:
#
# data.attributes.id cannot be written
# included..attributes.id cannot be written
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment