Asu
Asu

Reputation: 1843

Reducing output of GraphQL

I have set up a GraphQL-mongoose-express-apollo combo as per this guide.

When I run a query to get multiple results, is there a way to reduce the resulting array before I actually get to processing the response from the query.

Query:

query GetSomeUsers {
  userMany (limit: 3){
    _id
  }
}

Actual output:

{
  "data": {
    "userMany": [
      {
        "_id": "5e950543cb48dbaafc60722d"
      },
      {
        "_id": "5e950543cb48dbaafc60722e"
      },
      {
        "_id": "5e950547cb48dbaafc60722f"
      }
    ]
  }
}

Desired output:

{
  "data": {
    "userMany": [
        "5e950543cb48dbaafc60722d",
        "5e950543cb48dbaafc60722e",
        "5e950547cb48dbaafc60722f"
    ]
  }
}

So far I have only found something that seems to be relevant in an article on GraphQL Leveler, but I don't see how it would work with graphql-compose-mongoose, as the GraphQL schema is automatically generated and there does not seem to be any place in the code to put in that LevelerObjectType in place of a GraphQLObjectType.

Upvotes: 1

Views: 241

Answers (0)

Related Questions