Lighthouse: Using @group in "extend type" causes incorrectly nested types when using @paginate

Created on 15 Oct 2018  路  2Comments  路  Source: nuwave/lighthouse

Describe the bug

When using @paginate directive within an extend type Query @group the emitted schema is incorrect.

Introspection/Playground Schema:
image

Query examples:

{
  users(count: 5) {
    data { id email }
  }
}

# Error: Cannot query field \"id\" on type \"UserPaginator\".
{
  users(count: 5) {
    data { data { id email } }
  }
}

# Error: "Argument 1 passed to Nuwave\\Lighthouse\\Schema\\Types\\PaginatorField::dataResolver() must implement interface Illuminate\\Contracts\\Pagination\\LengthAwarePaginator, instance of App\\User given, called in test/vendor/nuwave/lighthouse/src/Schema/Directives/Fields/FieldDirective.php on line 52",

Expected behavior

Query example 1 should work fine and emitted schema should only contain UserPaginator and not UserPaginatorPaginator

Schema

type User {
    id: ID!
    email: String!
}
type Query {
    me: User @auth
}
extend type Query @group {
    users: [User!]! @paginate
}

Environment

Lighthouse Version: 2.3
Laravel Version: 5.7
PHP Version: 7.1

Additional context

Issue was introduced with Lighthouse 2.3. Downgrading to 2.2 fixes the issue.

bug

Most helpful comment

Added a pull-request that solves the issue for me and passes the unit test in the previous comment.

Hope it helps.

All 2 comments

Failing test:

/**
     * @test
     */
    public function itCanCreateQueryPaginatorsInGroup()
    {
        factory(User::class, 2)->create();

        $schema = '
        type User {
            id: ID!
            name: String!
        }

        type Query {
            dummy: Int
        }

        extend type Query @group {
            users: [User!]! @paginate(model: "User")
        }
        ';

        $query = '
        {
            users(count: 1) {
                data {
                    id
                    name
                }
            }
        }
        ';

        $result = $this->executeQuery($schema, $query);

        $this->assertCount(1, array_get($result->data, 'users.data'));
    }

This test fails on latest master (787baff47fcd8ac19fd1e6671e413b82f02d189e)
It does succeed, when downgrading DocumentAST.php to c405ad74

==> Issue was introduced with 2b4add91c281e71c8e7e28b71c82ab4c82eb1bb9

Added a pull-request that solves the issue for me and passes the unit test in the previous comment.

Hope it helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

basudebpalfreelancer picture basudebpalfreelancer  路  4Comments

spawnia picture spawnia  路  3Comments

eriktisme picture eriktisme  路  4Comments

spawnia picture spawnia  路  4Comments

vine1993 picture vine1993  路  3Comments