graphql-kit / graphql-lodash

🛠 Data manipulation for GraphQL queries with lodash syntax
https://apis.guru/graphql-lodash/
MIT License
1.23k stars 48 forks source link

missing functionality to flatten array #10

Closed MrLoh closed 6 years ago

MrLoh commented 6 years ago

I have the following query:

movie {
  cast {
    id
    role
    person {
      actorId: id
      fullName
    }
  }
}

Now I would like to flatten the cast into an array of not-nested objects.

movie {
  cast {
    id
    role
    actorId
    fullName
  }
}

It seems like lodash can't do that. Would be nice to add a functionality, maybe like:

movie {
  cast @_(flattenObjectDepth: 1) {
    id
    role
    person {
      actorId: id
      fullName
    }
  } 
}

I could create a PR, with a little help as to how transformations need to look like.

IvanGoncharov commented 6 years ago

@MrLoh I need to think about it and how to make it more readable. Maybe add separate @spread directive, like this:

movie {
  cast {
    id
    role
    person @spread {
      actorId: id
      fullName
    }
  } 
}

What do you think?

IvanGoncharov commented 6 years ago

@MrLoh On a second thought create separate directives for every transformation is a bad idea. Thanks to @RomanGotsiy for explaining this to me. Need to think a little bit more about this...

MrLoh commented 6 years ago

I like the spread idea, it's just a very common task in graphql I think, that's missing from lodash.

MrLoh commented 6 years ago

This would probably be best covered by #9 as well, maybe we should close this?

IvanGoncharov commented 6 years ago

@MrLoh Agree 🎉