Skip to content

Pass data from parent to child #2292

@Stevemoretz

Description

@Stevemoretz

I have asked this in stackoverflow and got some workaround as an answer https://stackoverflow.com/questions/75375487/laravel-lighthouse-pass-data-from-parent-to-child/75379321#75379321, but were thinking maybe there is a cleaner way maybe via using ResolveInfo .

So just wanted to make sure if the best way to send data to child is do that extra data from parent and get it as the first argument of child (the parent data) or is there a better way.

   public function parent(
        $_,
        array $args,
        GraphQLContext $context,
        ResolveInfo $resolveInfo
    ) {
        return [
            "extra_data_for_child" => true,
            "real_data" => [
                "real_stuff" => [
                    "real" => "1",
                ],
            ],
        ];
    }

    /**
     * @param null $_
     * @param array{} $args
     */
    public function child(
        $parent,
        array $args,
        GraphQLContext $context,
        ResolveInfo $resolveInfo
    ) {
        dd($parent['extra_data_for_child']); // true
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionRequest for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions