Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom :jsonapi parameter_parsers being overriden by graphiti-rails #106

Open
svobom57 opened this issue Sep 7, 2023 · 2 comments · May be fixed by #109
Open

Custom :jsonapi parameter_parsers being overriden by graphiti-rails #106

svobom57 opened this issue Sep 7, 2023 · 2 comments · May be fixed by #109

Comments

@svobom57
Copy link

svobom57 commented Sep 7, 2023

We are facing a peculiar issue where we override the jsonapi parser in order to make the incoming payload snake_case instead of camelCase.

We use a solution similar to the one proposed here:
graphiti-api/graphiti#286

where at some point we call:
ActionDispatch::Request.parameter_parsers[:jsonapi] = transformer

Now the problem is that graphiti-rails does the same thing here in the Railtie:

ActionDispatch::Request.parameter_parsers[:jsonapi] = PARSER

which then overrides our custom implementation if called after our custom initialisation.

We have this set up in quite a few repos but for one of our repos the initialisation process (for some reason I'm not sure of) is reversed and the order of the calls are as follows:

  1. Our custom initialiser is called
  2. graphiti-rails Railtie is called overriding our custom parser

I'm not quite sure what determines the order of the Railtie call and our initialisation but I'm thinking that perhaps the gem should be resilient to this and only assign the transformer if one does not already exist, i.e. instead of the current code:

      def register_parameter_parser
        if ::Rails::VERSION::MAJOR >= 5
          ActionDispatch::Request.parameter_parsers[:jsonapi] = PARSER
        else
          ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] = PARSER
        end
      end

run:

      def register_parameter_parser
        if ::Rails::VERSION::MAJOR >= 5
          ActionDispatch::Request.parameter_parsers[:jsonapi] ||= PARSER
        else
          ActionDispatch::ParamsParser::DEFAULT_PARSERS[Mime[:jsonapi]] ||= PARSER
        end
      end
@wagenet
Copy link
Collaborator

wagenet commented Jan 10, 2024

@svobom57 Unfortunately, I'm not working with Rails at my current job and have no bandwidth to help here. It looks like that may be true for the other contributors to this project as well. If you (or anyone else) have interest in picking up ownership, please let me know. Sorry!

@svobom57
Copy link
Author

@wagenet Opened up a PR here: #109 Let me know what else to do. 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants