thecodingmachine / graphqlite

Use PHP Attributes/Annotations to declare your GraphQL API
https://graphqlite.thecodingmachine.io
MIT License
555 stars 95 forks source link

Arguments description in schema #622

Closed downace closed 11 months ago

downace commented 11 months ago

Currently description is not supported for fields arguments.

I've tried to implement my own parameter middleware which takes description from the DocBlock:

// snip
if ($mappedParameter instanceof InputTypeParameter) {
    $paramTag = \Arr::first(
        $docBlock->getTagsByName('param'),
        fn(Param $paramTag) => $paramTag->getVariableName() === $parameter->getName(),
    );

    $desc = (string) $paramTag?->getDescription();

    $mappedParameter->setDescription($desc);
}
// snip
Expected result example ```php class ProductController { /** * @param ID $id The product id */ #[Query] public function product(ID $id): Product { // ... } } ``` ```graphql type Query { product( "The product id" id: ID! ): Product! } ```

But it's not working. I found that parameter description is ignored when creating QueryField from Descriptor, here:

https://github.com/thecodingmachine/graphqlite/blob/8d6a29248d7dc366815ce5e8677bd1e97bb9ae0b/src/InputTypeUtils.php#L115-L124

oojacoboo commented 11 months ago

@downace a PR would be welcomed for support. Does this include output type fields? An implementation should cover all fields, not just input type fields.

downace commented 11 months ago

@downace a PR would be welcomed for support

Sure, working on it.

Does this include output type fields? An implementation should cover all fields, not just input type fields.

AFAIK, descriptions are currently supported everywhere (via DocBlocks or annotation's description parameter) except fields arguments.

oojacoboo commented 11 months ago

AFAIK, descriptions are currently supported everywhere (via DocBlocks or annotation's description parameter) except fields arguments.

Yes, but fields can have arguments for input and output types, and those are two different types, which have different type mappers IIRC.