Type-graphql: Get list of requested fields

Created on 19 Jan 2019  路  1Comment  路  Source: MichalLytek/type-graphql

Hi!

Is it possible to get a list of requested fields? For example, user performs the following query:

{
    id
    user {
        id
        firstName
    }
}

And I would like to know what fields were requested by user, in FieldResolver for example:

@FieldResolver()
user(
    @Root() parent: ParentEntity,
    @RequestedFields() fields: string[],
) {
    /** if only id is requested, there's no need to execute unnecessary
      * request to the database, so I can just return:
      * { id: parent.user }
     **/
}

Maybe there's a better way to do it, but I couldn't find it yet.

Thanks!

Question Solved

Most helpful comment

See #10 - for now use @Info() and parse it manually.

>All comments

See #10 - for now use @Info() and parse it manually.

Was this page helpful?
0 / 5 - 0 ratings