1

GQL union query not getting me the results

Below is what I've done,

type Body {
  content: Content
}

union Content = TextContent | BannerContent

type TextContent {
  text: String
}

type BannerContent {
  banners: [Banner]
}

Front End Query,

query {
  someField {
    body {
      content: {
        ...on TextContent {
          text
        }
        ...on BannerContent {
          banners
        }

      }
    }
  }
}

My Resolver Function,

  async getBannerContent(_, { bannerType }, { injector }: ModuleContext) {
    try {
      const response = await injector.get(Crs).getBanner(bannerType);
      return response.body[0];
    } catch (err) {}
  }

In Front end I'm getting response as null for Content.

Please help.

Note:- I'm using GQL modules.

aw3123
  • 139
  • 5
  • 18
  • If you log `esponse.body[0]` is it defined? Does it contain the appropriate value (either an object with a `text` property or a `banners` property)? Have you defined a `resolveType` function for your union? – Daniel Rearden Feb 06 '20 at 13:03

0 Answers0