Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to flat query result?

Tags:

graphql

With a sample make it easy understand, with https://developer.github.com/v4/explorer/

query the viewer info:

query {
  viewer {
    followers {
      totalCount
    }
    following {
      totalCount
    }
  }
}

the result is:

{
  "data": {
    "viewer": {
      "followers": {
        "totalCount": 131
      },
      "following": {
        "totalCount": 28
      }
    }
  }
}

what I want is:

{
  "data": {
    "viewer": {
      "followersCount" 131,
      "followingCount": 28
    }
  }
}

so does GraphQL support this ? and how to do it?

like image 827
goodev Avatar asked Jun 14 '17 02:06

goodev


People also ask

What does it mean to flatten SQL?

FLATTEN is a table function that takes a VARIANT, OBJECT, or ARRAY column and produces a lateral view (i.e. an inline view that contains correlation referring to other tables that precede it in the FROM clause). FLATTEN can be used to convert semi-structured data to a relational representation.

What is [] in SQL query?

The brackets are required if you use keywords or special chars in the column names or identifiers. You could name a column [First Name] (with a space) – but then you'd need to use brackets every time you referred to that column. The newer tools add them everywhere just in case or for consistency.


1 Answers

GraphQL doesn't support this type of data flattening.
You must change the data structure in your code or work with the returned data structure.


EDIT: I just came across this repository (graphql-lodash) that could help you achieve what you want.

like image 149
yachaka Avatar answered Oct 24 '22 19:10

yachaka