java—向micronaut graphql发送数组以从reactjs进行查询

bqjvbblv  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(338)

我试图将一个字符串数组从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);
}

我可以打印年龄,但姓名打印为空。我做错什么了吗?我试过用arraylist代替list,但仍然无法正确接收名称。希望您能提供帮助。谢谢!

g2ieeal7

g2ieeal71#

它是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}))

相关问题