thecodingmachine / graphqlite

Use PHP Attributes/Annotations to declare your GraphQL API

Home Page:https://graphqlite.thecodingmachine.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Arguments description in schema

downace opened this issue · comments

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
class ProductController {
    /**
     * @param ID $id The product id
     */
    #[Query]
    public function product(ID $id): Product {
        // ...
    }
}
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:

return array_map(static function (InputTypeParameterInterface $parameter): array {
$desc = [
'type' => $parameter->getType(),
];
if ($parameter->hasDefaultValue()) {
$desc['defaultValue'] = $parameter->getDefaultValue();
}
return $desc;
}, $inputTypeArgs);

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

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.