From dacfe5ea348f966093a952d370cb40d00fa3707c Mon Sep 17 00:00:00 2001 From: Kyle Brenneman Date: Fri, 25 Feb 2022 15:06:55 -0700 Subject: [PATCH 1/2] allow subclassing Connection without having to implement abstract constants in the subclass --- src/Codegen/Generator.hack | 6 +++++- src/Pagination/Connection.hack | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Codegen/Generator.hack b/src/Codegen/Generator.hack index f68c762..ae2bde3 100644 --- a/src/Codegen/Generator.hack +++ b/src/Codegen/Generator.hack @@ -242,7 +242,11 @@ final class Generator { } foreach ($classish_objects as $class) { - if (\is_subclass_of($class->getName(), \Slack\GraphQL\Pagination\Connection::class)) { + $rc = new \ReflectionClass($class->getName()); + if ( + \is_subclass_of($class->getName(), \Slack\GraphQL\Pagination\Connection::class) && + $rc->getAttributeClass(\Slack\GraphQL\ObjectType::class) + ) { invariant( Str\ends_with($class->getName(), 'Connection'), "All connection types must have names ending with `Connection`. `%s` does not.", diff --git a/src/Pagination/Connection.hack b/src/Pagination/Connection.hack index 1328d09..350bd1c 100644 --- a/src/Pagination/Connection.hack +++ b/src/Pagination/Connection.hack @@ -50,6 +50,7 @@ type PaginationArgs = shape( * @see https://relay.dev/graphql/connections.htm for more information about GraphQL pagination. * @see src/playground/UserConnection.hack for an example. */ + <> abstract class Connection { /** @@ -57,6 +58,7 @@ abstract class Connection { * * This should be the Hack class over which you want to paginate. */ + <<__Enforceable>> abstract const type TNode; /** From 375a51a5da92df8b77c35e3ee0fe91dcc7a9ff49 Mon Sep 17 00:00:00 2001 From: Kyle Brenneman Date: Fri, 25 Feb 2022 15:34:40 -0700 Subject: [PATCH 2/2] remove annotation --- src/Pagination/Connection.hack | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Pagination/Connection.hack b/src/Pagination/Connection.hack index 350bd1c..2567a04 100644 --- a/src/Pagination/Connection.hack +++ b/src/Pagination/Connection.hack @@ -50,7 +50,6 @@ type PaginationArgs = shape( * @see https://relay.dev/graphql/connections.htm for more information about GraphQL pagination. * @see src/playground/UserConnection.hack for an example. */ - <> abstract class Connection { /**