Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 1.05 KB

typesafe-client-multiple-queries.md

File metadata and controls

45 lines (36 loc) · 1.05 KB

Multiple

Say you need the result from several root queries, e.g. all superHeroes and all superVillains. Java only supports a single return value, so you’ll need a wrapper class:

@GraphQLClientApi
interface SuperHeroesApi {
    HeroesAndVillains heroesAndVillains();
}

@Multiple
class HeroesAndVillains {
    List<SuperHero> superHeroes;
    List<SuperVillain> superVillains;
}

The @Multiple annotation 'inlines' the wrapper class, i.e. the actual query is:

query heroesAndVillains { superHeroes {...} superVillains {...}}

The actual response below will be mapped to an instance of the HeroesAndVillains wrapper class:

{
  "data": {
    "superHeroes": [ ... ],
    "superVillains": [ ... ]
  }
}

If the nested queries require parameters, use @ annotations to put them on the field (remember: GraphQL fields can have parameters).

If you need the same request several times (e.g. with different query parameters), use @Name annotations, so the actual field names are used as alias.