I'm trying to send an array of strings from reactjs to micronaut, to test if the data is being successfully passed, I have something like this in the frontend:
const [filterName, setName] = useState(["test"]);
const age = 1;
const { data: people } = useSWR([`
query ($name:[String], $age:Int){
getName(name:$name, age:$age){ ... }`, filterName, age], (query, filterName, age) => fetcher(query, {filterName, age}))
My micronaut backend looks something like this:
@GraphQLQuery(name = "getName")
List<User> getName (@GraphQLArgument(name = "name") List<String> name,
@GraphQLArgument(name = "age") Integer age ){
System.out.println("name: " + name.toString());
System.out.println("age: " + age);
}
I can print the age but the name prints null. Am I doing something wrong? I've tried using ArrayList instead of List, still can't receive the name properly.I hope you can help. Thanks!
It was the variables inside fetcher. It needed to match the api name declared in micronaut. It should've been like this:
const [filterName, setName] = useState(["test"]);
const age = 1;
const { data: people } = useSWR([`
query ($name:[String], $age:Int){
getName(name:$name, age:$age){ ... }`, filterName, age], (query, filterName, age) => fetcher(query, {name:filterName, age}))