Skip to content

Commit

Permalink
Fix connection codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
ianhoffman committed Sep 27, 2021
1 parent 9446546 commit a530973
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Codegen/Generator.hack
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,12 @@ final class Generator {
}

foreach ($classish_objects as $class) {
if (Str\ends_with($class->getName(), 'Connection')) {
// TODO: Assert that any class which subclasses Connection<T> has a name ending in `Connection`.
if (\is_subclass_of($class->getName(), \Slack\GraphQL\Pagination\Connection::class)) {
invariant(
Str\ends_with($class->getName(), 'Connection'),
"All connection types must have names ending with `Connection`. `%s` does not.",
$class->getName(),
);
$objects = Vec\concat($objects, $this->getConnectionObjects($class));
} elseif (!C\is_empty($class->getAttributes())) {
$rc = new \ReflectionClass($class->getName());
Expand Down Expand Up @@ -327,7 +331,6 @@ final class Generator {

private function getConnectionObjects(DefinitionFinder\ScannedClassish $class): vec<ObjectBuilder> {
$rc = new \ReflectionClass($class->getName());
invariant(is_connection_type($rc), '"%s" must subclass "Connection"', $rc->getName());
$hack_type = $rc->getTypeConstants()
|> C\find($$, $c ==> $c->getName() === 'TNode')?->getAssignedTypeText();
invariant($hack_type is nonnull, '"%s" must declare a type constant "TNode"', $rc->getName());
Expand Down

0 comments on commit a530973

Please sign in to comment.