Skip to content

Instantly share code, notes, and snippets.

@nachokb
Last active September 20, 2019 01:29
Show Gist options
  • Save nachokb/4aaf2116cd738b1a745197c94b7da1bf to your computer and use it in GitHub Desktop.
Save nachokb/4aaf2116cd738b1a745197c94b7da1bf to your computer and use it in GitHub Desktop.
Generating links with Graphiti
class ScoringResource < ApiResource
has_many :reviews
extra_attribute :employee_name, :string, only: :readable do
@object.compute_employee_name
end
filter :company_id_and_date, :string do
# custom eq
end
end
class ReviewResource < ApiResource
attribute :scoring_id,
:integer,
only: :filterable
belongs_to :scoring
attribute :approved,
:boolean
end
class ApiResource < 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
{
"data": [{
"id": "2",
"type": "scorings",
"attributes": {
"employee_id": 76,
"date": "2019-09-19",
"comments": null,
"employee_name": "A B C"
},
"relationships": {
"reviews": {
"meta": {
"included": false
}
}
}
}, {
"id": "6",
"type": "scorings",
"attributes": {
"employee_id": 75,
"date": "2019-09-19",
"comments": null,
"employee_name": "M N O"
},
"relationships": {
"reviews": {
"meta": {
"included": false
}
}
}
}],
"meta": {}
}
@nachokb
Copy link
Author

nachokb commented Sep 20, 2019

I was getting a Graphiti::Errors::InvalidLink error masked by a Rails missing template error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment