How to avoid a nested query?

127 Views Asked by At

In Sangria I'm getting a list of users by IDs

lazy val UsersType: ObjectType[GraphQLContext, Seq[User]] = ObjectType("users", () =>
fields[GraphQLContext, Seq[User]](
    Field("users", ListType(UserDetailType), resolve = 
    _.value),
))

The Query works, but I have to write the name of the Query and the name of the Field "users" twice, they are the same.

The Query now is:

users(id: 123) {
    users {
        id
        name
    }
}

How to avoid the need to type the query name and the field name? How to turn the query to:

users(id: 123) {
    id
    name
}
1

There are 1 best solutions below

1
On BEST ANSWER

Just use ListType(UsersType) in schema