Created
August 17, 2020 14:57
-
-
Save apauly/f44886f9abd86a818d23090988a8e861 to your computer and use it in GitHub Desktop.
Graphiti requires writable id also for relations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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