Skip to content

Support Generics style PHPDoc @return typing #436

Description

@oojacoboo

When returning a Collection, you can annotate the @return type like:

/**
 * @return Article[]
 */
#[GraphQLite\Field]
public function getArticles(): Collection; 

However, this doesn't tell many static analyzers that the return type is a Collection. Maybe some smarter analyzers will check the actual return type, if typed, and use both combined. I'm unsure about that. But, there is value in using the Generics syntax for those that don't.

/**
 * @return Collection<Article>
 */
#[GraphQLite\Field]
public function getArticles(): Collection;

This syntax is quickly becoming somewhat of a standard at this point. It's supported by Psalm, Phan, PHPStan and I'm sure others. It was implemented by PHPStorm.

Many of you are probably familiar with this syntax and probably use it. For compatibility reasons, we should support both of these syntaxes when evaluating an @return annotation for the sake of generating GraphQL Types. Currently, an error is thrown as it tries to create a Type definition out of Collection

Activity

  1. changed the title [-]Support Generics style PHPDoc return typing[/-] [+]Support Generics style PHPDoc @return typing[/+] on Jan 20, 2022
  2. Lappihuan commented on Apr 22, 2022

    @Lappihuan
    Contributor

    wouldn't #321 fix this?

  3. oojacoboo commented on Apr 22, 2022

    @oojacoboo
    CollaboratorAuthor

    @Lappihuan yes, probably so - we need tests there to confirm.

  4. oojacoboo commented on Jun 12, 2022

    @oojacoboo
    CollaboratorAuthor

    Generics support was added with #468 and released with version 6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions