uesteibar / neuron

A GraphQL client for Elixir
https://hex.pm/packages/neuron
Other
331 stars 35 forks source link

Converting underscored keys to mixed case keys in mutation arguments #68

Closed brainlid closed 3 years ago

brainlid commented 3 years ago

tl;dr

It appears that when making a request with Neuron to a Rails GraphQL API, there is no conversion (or config options for it that I could find) to deal with how a key is translated. I want to send a snake-case key like my_special_key and have it submitted as mySpecialKey.

This is an issue with arguments being submitted in a mutation for example.

Is this possible or already available?

More detailed:

The API I'm talking to expects a key to be called "organizationId". It fails if I send a map like this:

%{organization_id: "my-id"}

The server isn't adapting to it and I haven't seen how to tell the Neuron client to do something different with it. I have to send:

%{organizationId: "my-id"}

I can deal with that for simple data, but I also have data that passes a large, deeply nested Elixir map. I'd have to convert all the keys before sending.

Is there a built-in way to deal with this? A parser option or something I didn't see?

uesteibar commented 3 years ago

there's no option for this and I prefer not to add it. if you need this you might want to add your own json library instead? one that would take the map and do this conversion.

brainlid commented 3 years ago

Ok. Thanks for letting me know that there is no built-in support for it.

brainlid commented 3 years ago

NOTE: For others who find this request.

I ended up using recase for help with pre-processing the arguments. https://github.com/sobolevn/recase