This repository was archived by the owner on Apr 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
[POC] Allow Graphiti usage for api requests to be optional #53
Open
caseyprovost
wants to merge
35
commits into
graphiti-api:master
Choose a base branch
from
caseyprovost:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
e0de65e
Try to optionally use Graphiti
caseyprovost d584c9d
Update railtie.rb
caseyprovost 615dfea
Update railtie.rb
caseyprovost 57bf66a
Update railtie.rb
caseyprovost 7708b82
Update jsonapi_serializable_ext.rb
caseyprovost 9930576
Update jsonapi_serializable_ext.rb
caseyprovost 9dafc61
Update jsonapi_serializable_ext.rb
caseyprovost bf0edd5
Update jsonapi_serializable_ext.rb
caseyprovost 21c29a1
Update jsonapi_serializable_ext.rb
caseyprovost 5d05d39
Update jsonapi_serializable_ext.rb
caseyprovost a42b009
Update jsonapi_serializable_ext.rb
caseyprovost b6305d1
Update jsonapi_serializable_ext.rb
caseyprovost b09365c
Try to optionally use Graphiti
caseyprovost f630152
Update railtie.rb
caseyprovost 64b00f1
Update railtie.rb
caseyprovost 9d7b072
Update railtie.rb
caseyprovost 3c3eeed
Update jsonapi_serializable_ext.rb
caseyprovost d05f502
Update jsonapi_serializable_ext.rb
caseyprovost 28a93c4
Update jsonapi_serializable_ext.rb
caseyprovost 309e51a
Update jsonapi_serializable_ext.rb
caseyprovost d12d353
Update jsonapi_serializable_ext.rb
caseyprovost 0c9b589
Update jsonapi_serializable_ext.rb
caseyprovost 94b4437
Update jsonapi_serializable_ext.rb
caseyprovost 45b50af
Update jsonapi_serializable_ext.rb
caseyprovost f40bf64
Merge branch 'master' of https://github.com/caseyprovost/graphiti
caseyprovost ee5f2b5
Merge remote-tracking branch 'upstream/master'
caseyprovost 9cd6908
debugging
caseyprovost 06948a9
working through bugs
caseyprovost fc0bebb
reverting changes
caseyprovost d2b87e3
working through compatibility
caseyprovost 4a60843
maybe prepend is the direction we want to go
caseyprovost 0750f11
add debug info
caseyprovost a167a76
pry debugging
caseyprovost 64051af
work around JSONAPI-RAILS
caseyprovost 37e7d1e
remove comments
caseyprovost File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,8 @@ class Railtie < ::Rails::Railtie | |
| end | ||
| end | ||
|
|
||
| if Mime[:jsonapi].nil? # rails 4 | ||
| Mime::Type.register('application/vnd.api+json', :jsonapi) | ||
| if Mime[:graphiti].nil? # rails 4 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is OK to make this a configuration option, but not a default. The majority of our users do not run both gems at the same time, and I think |
||
| Mime::Type.register('application/vnd.api+json', :graphiti) | ||
| end | ||
| register_parameter_parser | ||
| register_renderers | ||
|
|
@@ -39,22 +39,22 @@ class Railtie < ::Rails::Railtie | |
| # from jsonapi-rails | ||
| PARSER = lambda do |body| | ||
| data = JSON.parse(body) | ||
| data[:format] = :jsonapi | ||
| data[:format] = :graphiti | ||
| data.with_indifferent_access | ||
| end | ||
|
|
||
| def register_parameter_parser | ||
| if ::Rails::VERSION::MAJOR >= 5 | ||
| ActionDispatch::Request.parameter_parsers[:jsonapi] = PARSER | ||
| ActionDispatch::Request.parameter_parsers[:graphiti] = PARSER | ||
| else | ||
| ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] = PARSER | ||
| ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:graphiti]] = PARSER | ||
| end | ||
| end | ||
|
|
||
| def register_renderers | ||
| ActiveSupport.on_load(:action_controller) do | ||
| ::ActionController::Renderers.add(:jsonapi) do |proxy, options| | ||
| self.content_type ||= Mime[:jsonapi] | ||
| ::ActionController::Renderers.add(:graphiti) do |proxy, options| | ||
| self.content_type ||= Mime[:graphiti] | ||
|
|
||
| opts = {} | ||
| if respond_to?(:default_jsonapi_render_options) | ||
|
|
@@ -70,8 +70,8 @@ def register_renderers | |
| end | ||
|
|
||
| ActiveSupport.on_load(:action_controller) do | ||
| ::ActionController::Renderers.add(:jsonapi_errors) do |proxy, options| | ||
| self.content_type ||= Mime[:jsonapi] | ||
| ::ActionController::Renderers.add(:graphiti_errors) do |proxy, options| | ||
| self.content_type ||= Mime[:graphiti] | ||
|
|
||
| validation = GraphitiErrors::Serializers::Validation.new \ | ||
| proxy.data, proxy.payload.relationships | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do
resources = Array(resources)here so we don't have to do it further down the line?