将数组发送到 Micronaut Graphql 以从 ReactJS 进行查询
Sending an array to Micronaut Graphql for query from ReactJS
我正在尝试将一个字符串数组从 reactjs 发送到 micronaut,以测试数据是否已成功传递,我在前端有这样的东西:
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}))
我的 micronaut 后端看起来像这样:
@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);
}
我可以打印 age 但 name 打印 null。难道我做错了什么?我试过使用 ArrayList 而不是 List,仍然无法收到名称 properly.I 希望你能帮忙。谢谢!
是fetcher里面的变量。它需要匹配 micronaut 中声明的 api 名称。应该是这样的:
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}))
我正在尝试将一个字符串数组从 reactjs 发送到 micronaut,以测试数据是否已成功传递,我在前端有这样的东西:
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}))
我的 micronaut 后端看起来像这样:
@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);
}
我可以打印 age 但 name 打印 null。难道我做错了什么?我试过使用 ArrayList 而不是 List,仍然无法收到名称 properly.I 希望你能帮忙。谢谢!
是fetcher里面的变量。它需要匹配 micronaut 中声明的 api 名称。应该是这样的:
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}))