Apollo-android: [Code Generation] Union fragment has extra non-nullability check

Created on 26 Jun 2019  路  2Comments  路  Source: apollographql/apollo-android

The GraphQL server has a shapes field which returns a list of Shapes. In version 1, Shape is a union of Square and Circle. In version 2 of schema, we add a new type Triangle to the union so Shape is now a union of Square, Circle and Triangle.

The Android client demo code here is built against the v1 schema and it crashed when the server updates to v2.

This is the original query

query Shapes {
  shapes {
    ...Shape
  }
}

fragment Shape on Shape {
  ...Square
  ...Circle
}

fragment Square on Square {
  name
}

fragment Circle on Circle {
  name
}

If we change the query to the following, it works after server upgrade.

query Shapes {
  shapes {
    ...Square
    ...Circle
  }
}

fragment Square on Square {
  name
}

fragment Circle on Circle {
  name
}

The gerenated code for the query has a non-null check on the Shape fragment. This is where the client crashes after the server is upgraded to v2 (with a new type in the Shape union).

Is this behavior expected?

compiler Bug

Most helpful comment

Seems like a bug, will investigate it

All 2 comments

Seems like a bug, will investigate it

This issue might be closed via this PR: https://github.com/apollographql/apollo-android/pull/1410
And it seems it's a duplicate of https://github.com/apollographql/apollo-android/issues/1344

I'm closing it for now, but feel free to reopen if it's still the case.

Was this page helpful?
0 / 5 - 0 ratings