Skip to content

Resolver Array type with key value #887

Answered by matasarei
darkiron asked this question in Q&A
Discussion options

You must be logged in to vote

Its long time but anyway here is possible solution:

class KeyValue extends ObjectType
{
    public function __construct()
    {
        parent::__construct([
            'name' => 'KeyValue',
            'fields' => [
                'key' => [
                    'type' => Type::nonNull(Type::string()),
                    'resolve' => static fn($rootValue) => $rootValue['key'],
                ],
                'value' => [
                    'type' => Type::nonNull(Type::string()),
                    'resolve' => static fn($rootValue) => $rootValue['value'],
                ],
            ],
        ]);
    }
}

In your type add a new field:

    'fields' => [
        'list' => [
    …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@spawnia
Comment options

Answer selected by spawnia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #886 on July 09, 2021 15:32.