json-to-graphql-query icon indicating copy to clipboard operation
json-to-graphql-query copied to clipboard

add support for Apollo @rest directive

Open KitoC opened this issue 5 years ago • 2 comments

Issue Apollo rest-link uses the @rest directive to to determine if it is a rest query/mutation with a range of config passed into the args of the directive ( e.g. @rest(path: "/foo")). Currently if you want to use both __directive and __args for the same key, json-to-graphql-query will generate the following directive and arg shape foo @rest(directive: args) (real: args). Apollo requires you to construct it like this - foo (real: args) @rest(directive: args).

Additionally, as far as I am aware, there doesn't seem to be any reason for stripping the quotes " from the args passed into the directive. Currently if you want to have a string in the directive args you cannot.

Solution

  1. Add a conditional to check for an @rest directive and place the args in front if @rest is present.
  2. remove the quote replacer

This is my first time contributing to open source projects so if there is anything I missed please let me know 😁 👍 .

KitoC avatar Oct 15 '19 10:10 KitoC

Thanks @KitoC - apologies for not having looked at this, I'm not doing much JS at the moment! I will try to take a look in the next week or so :)

dupski avatar Jan 27 '20 06:01 dupski

Hi @KitoC - just had a look at this (again, apologies for how long this has taken, particularly as it was your first contribution!!). I think we need something a bit more generic than tie-ing it to a specific directive name.

I wonder if we should just add an extra key in the directive args object, e.g. __position which could take "beforeArgs" or "afterArgs" as a value to control the position of the directive.

dupski avatar Feb 03 '20 02:02 dupski