Skip to content

How can I receive fields for 'resolve' ? #95

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nepster-web opened this issue Mar 10, 2017 · 2 comments
Closed

How can I receive fields for 'resolve' ? #95

nepster-web opened this issue Mar 10, 2017 · 2 comments

Comments

@nepster-web
Copy link

My query is:

      $queryString = '{
            Record(id: "7") {
                id,
                alias,
                visible
            }
        }';

My ContentSchema is:

        $queryType = new ObjectType([
            'name' => 'Query',
            'fields' => [
                'Record' => [
                    'type' => $contentType,
                    'args' => [
                        'id' => Type::string(),
                        'alias' => Type::string(),
                    ],
                    'resolve' => function ($v, $a, $c, ResolveInfo $info) {

                        // need get query fields list:  id, alias, visible
                        // and execute optimal query to my store 
                       // $store->find()->select(['id', 'alias', 'visible'])->all();

                    },
                ],
            ],
        ]);

How can I get a list of requested fields to build optimal query?

@vladar
Copy link
Member

vladar commented Mar 10, 2017

You can use $info->getFieldSelection() for now. See comments on how to use it.

But it will be likely deprecated in favor of #65 one day (no timeline set yet). We deprecate things without breaking usually (by issuing E_USER_DEPRECATED warning), so you will have time to migrate when it happens.

Or you can implement #65 yourself and submit a PR %)

@vladar vladar closed this as completed Mar 10, 2017
@nepster-web
Copy link
Author

Oh, thank you very much.

I know GraphQL and this library badly, but maybe I will think up something later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants