Skip to content

Conversation

klavs
Copy link
Contributor

@klavs klavs commented Feb 23, 2020

  • add __typename field to object and interface definitions
  • add some fragment-related tests

final type = shape.$__typename;
final area = shape.area;

final square = shape.asSquare();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smkhalsa, here's the API I originally imagined. What do you think? I like this approach because it lets user avoid using generated classes directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor note: if we did this, we'd probably want to prefix the asSubclass() methods with $ to avoid collisions with data fields.

What I like about using the generated subclasses directly is that if (class is classAsSubclass) feels intuitive and doesn't require any additional typecasting.

That said, if we did go this route, it would feel more intuitive to me to also have a $isSubclass property rather than checking for null with the $asSubclass() method.

if (shape.$isSquare) {
  final square = shape.$asSquare();
  return "$type(area: $area, sideLength: ${square.sideLength})";
}

if (shape.$isRectangle) {
  final rectangle = shape.$asRectangle();
  return "$type(area: $area, sideLengthA: ${rectangle.sideLengthA}, sideLengthB: ${rectangle.sideLengthB})";
}

@klavs klavs force-pushed the improve-fragment-support branch from d592e79 to 64dfaeb Compare February 26, 2020 20:57
@klavs klavs changed the base branch from actions-on-examples to master February 26, 2020 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants