Let's assume the following (pseudo)code:
@GraphQLQuery(name = "zooAnimals")
public List<IAnimal> getZooAnimals(Zoo zoo) {
// Get a list of animals here
}
public interface IAnimal {
// some animal code
}
public class Llama extends IAnimal {
// some llama code
}
@GraphQLQuery(name = "enclosureType")
public String getEnclosureType(@GraphQLContext LLama llama) {
// I need access to the Zoo object here
}
In the example above the type of enclosure for a llama depends on the type of zoo the llama is in. If the zoo is a Safari park the llama might be in a meadow, in a smaller zoo it might be in a cage.
In any case: I need to get access to the Zoo object within the getEnclosureType method.
I have no clue on how to achieve this. I tried modifying both the getZooAnimals query and the getEnclosureType query to gain access to the Resolution environment and pass the argument via the environment, like the example below. That unfortunately does not work, so I've ran out of options. The modifications I tried:
@GraphQLQuery(name = "zooAnimals")
public List<IAnimal> getZooAnimals(Zoo zoo, @GraphQLEnvironment ResolutionEnvironment env) {
// Get a list of animals here
env.arguments.put("zoo", zoo);
}
@GraphQLQuery(name = "enclosureType")
public String getEnclosureType(@GraphQLContext LLama llama, @GraphQLEnvironment ResolutionEnvironment env) {
// I need access to the Zoo object here
env.arguments.get("zoo"); // this returns null, as the arguments list is empty.
}