Given the set of types of GraphQL variables, is it possible to use a client schema to create a map of all valid values ​​for each type in the set

The name basically says it all: I am creating a response / relay application that will allow the user to dynamically create diagrams at runtime, displaying their various revenue streams over a specific time interval. One feature of this diagram is the ability of the user to specify the sampling interval for each flow proceeds (e.g., YEAR, QUARTER, MONTH, WEEKetc.) as a parameter for each flow.

These values ​​are defined in the schema as an instance GraphQLInputObjectTypeas follows:

enum timeSeriesIntervalEnum {
  YEAR
  QUARTER
  MONTH
  WEEK
}

On the client side, I have fragments react-relaydefined from the following form:

fragment on BalanceSheet {
  income {
    # some income stream
    afterTax {  
      values(interval: $samplingInterval)
      dates(interval: $samplingInterval)
    }
  }
}

, timeSeriesIntervalEnum.

, , API , , (, timeSeriesIntervalEnum), graphql json (pre-runtime), .

. , json , .

+4
1

, .

:

{
    __type(name: "timeSeriesIntervalEnum") {
    name
    enumValues {
      name
    }
  }
}

:

{
  "data": {
    "__type": {
      "name": "timeSeriesIntervalEnum",
      "enumValues": [
        {
          "name": "YEAR"
        },
        {
          "name": "QUARTER"
        },
        {
          "name": "MONTH"
        },
        {
          "name": "WEEK"
        }
      ]
    }
  }
}
+2

Source: https://habr.com/ru/post/1667699/


All Articles