Search code examples
scalagraphqlslicksangria

How to avoid a nested query?


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
}

Solution

  • Just use ListType(UsersType) in schema