absinthe-graphql / absinthe_relay

Absinthe support for the Relay framework
MIT License
182 stars 88 forks source link

Absinthe.Relay.Node.ParseIDs causes runtime error if occurs more than once in a mutation query #163

Closed jacobparry closed 4 years ago

jacobparry commented 4 years ago

Absinthe.Relay.Node.ParseIDs causes runtime error if occurs more than once in a mutation query.

This happens because in mutation.ex, __parse_ids_root is set at a global level on the resolution.

Once the ParseIDs.ex middleware is hit, it works great from a parent mutation but if ParseIDs is called in any of the child fields it blows up because it is expecting input to be set when it isn't for the child field.

This does two things:

  1. pattern matches on find_schema_root! so that it will identify if it is the parent mutation by matching on the
    %{
           __private__: [
             absinthe_relay: [
               payload: {:fill, _},
               input: {:fill, _}
             ]
           ]
         }

    structure.

The other pattern-match function is for the child fields.

  1. There was a discrepancy between the modern.ex and classic.ex modules in that the absinthe_relay: list was being generated in a different order.

For modern, it was getting generated as:

  absinthe_relay: [
               payload: {:fill, _},
               input: {:fill, _}
             ]

And classic was getting generated as:

  absinthe_relay: [
               input: {:fill, _},
               payload: {:fill, _} 
             ]

I reordered the macro in the classic.ex so that the list generated will be the same for both modern and classic and enable the pattern-match to work.

jacobparry commented 4 years ago

@benwilson512 what do you think of the changes and tests now?

benwilson512 commented 4 years ago

This is great, thank you!!!