1
votes

Knowing the schema (fetched via getIntrospectionQuery), how could I get the type of a particular field?

For example, say I run this query:

query {
  User {
    name
    lastUpdated
    friends {
      name
    }
  }
}

and get this result:

{
  "data": {
    "User": [
      {
        "name": "alice",
        "lastUpdated": "2018-02-03T17:22:49+00:00",
        "friends": []
      },
      {
        "name": "bob",
        "lastUpdated": "2017-09-01T17:08:49+00:00",
        "friends": [
          {
            "name": "eve"
          }
        ]
      }
    ]
  }
}

I'd like to know the types of the fields and construct something like this:

{
  "name": "String",
  "lastUpdated": "timestamptz",
  "friends": "[Friend]"
}

How could I do that without extra requests to the server?

1

1 Answers

0
votes

After retrieving the schema, you can build it into a JSON object (if your graphql framework does not do it already for you).

Using a JSON parser, you can retrieve the the types of each field.

I will not enter into the detail, as it would depend on the technology your are using.