Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fragment generation tests #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

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 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