GraphQL - Using same field names in different types within union

后端 未结 2 1874
悲哀的现实
悲哀的现实 2021-01-02 00:09

If I have a union type like this:

union AllOnboardingQuestionTypes = StepFinal | TimeRangesQuestion | PercentQuestion | SingleSelectQuestion | MultiSelectQu         


        
相关标签:
2条回答
  • 2021-01-02 00:59

    is this the right way to do the query?

    Yes. Unions are restricted in this way according to the current (June2018) GraphQL specification. See also a corresponding issue on graphql.js

    The aliases seem cumbersome

    The best way to avoid this is for the schema to specify different field names when the return types differ.

    0 讨论(0)
  • 2021-01-02 01:03

    I had the same problem and find three different solutions to it:

    1. Using Interface
    2. Using Union
    3. Using a String with additional type information

    All not very nice but working. I put a simple example project with all solutions on Github: https://github.com/chnoack/apollo-dynamic-types-example

    0 讨论(0)
提交回复
热议问题