Last active
August 17, 2020 14:31
-
-
Save apauly/1991e741fcec159632ef6e34866909c9 to your computer and use it in GitHub Desktop.
Graphiti id attribute with writable: false
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 PostResource < Graphiti::Resource | |
attribute :id, :integer_id, writable: false | |
attribute :title, :string, writable: true | |
end | |
params = { | |
data: { | |
id: 123, | |
type: 'posts', | |
attributes: { title: 'Hello World' } | |
} | |
} | |
begin | |
resource = PostResource.find(params) | |
rescue Graphiti::Errors::InvalidRequest => e | |
puts e.message | |
end | |
# Will print | |
# There were one or more errors with your request: | |
# | |
# data.attributes.id cannot be written |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment