Skip to content

Instantly share code, notes, and snippets.

@apauly
Last active August 17, 2020 14:31
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/1991e741fcec159632ef6e34866909c9 to your computer and use it in GitHub Desktop.
Save apauly/1991e741fcec159632ef6e34866909c9 to your computer and use it in GitHub Desktop.
Graphiti id attribute with writable: false
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