How to do runtime data manipulation over a field in graphQL?

I have a following query,

query
{
  snapshots {
    name
    timestamp
    aggregations {
      rating
      technology {
        name
        category {
          name
        }
      }
      trend
    }
  }
}

trend is not a field in database, I wish to calculate the value of this field on runtime and return, Is there any way that I can do it using graphQL?

I am looking for some way by which I can associate a function to trend property in this query and do anything in that function, comparison calculation or anything. for eg

query
{
  snapshots(limit: 1, sort: "timestamp:desc") {
    name
    timestamp
    aggregations {
      rating
      technology {
        name
        category {
          name
        }
      }
      trend: function (() => { 
      // do some calculation or comparison or some sub query here
     })
    }
  }
}

I cannot modify anything in database or on API for which this graphQL query is written.

1 answer

  • answered 2019-03-14 07:10 MarcoDaniels

    In GraphQL you can only manipulate data on the Server (with resolvers).

    If you don't have access to modify the GraphQL resolver on the server, I'm afraid you cannot accomplish what you're describing.