Javascript 如何在Apollo中获取数组?
让我们想象一下,我们的服务器上有这样一个模式,其中包含一个查询,该查询仅根据传递的名称参数获取主题列表Javascript 如何在Apollo中获取数组?,javascript,graphql,apollo,react-apollo,Javascript,Graphql,Apollo,React Apollo,让我们想象一下,我们的服务器上有这样一个模式,其中包含一个查询,该查询仅根据传递的名称参数获取主题列表 Query listTopics( name: String! ): [Topic!]! type Topic { id: String! name: String! image: String timeBasedFeed: String! scoreBasedFeed: String! aliases: [String!]! parents: [String!]! allAncestors
Query listTopics(
name: String!
): [Topic!]!
type Topic {
id: String!
name: String!
image: String
timeBasedFeed: String!
scoreBasedFeed: String!
aliases: [String!]!
parents: [String!]!
allAncestors: [String!]!
}
在获取数据时,如何声明查询在客户端上返回数组
当我们处理返回对象等的查询时,我们可以做下一件事
import { gql, useQuery } from '@apollo/client';
const GET_DOG = gql`
query GetDog {
// Declare response fields
id
name
}
`;
但是,当查询返回数组时,如何执行相同的操作
我试着这样做
import { gql } from '@apollo/client';
export const LIST_TOPICS_QUERY = gql`
query listTopics($name: String!) {
[
id,
name,
image,
timeBasedFeed,
storeBasedFeed,
aliases,
parents,
allAncestors
]
}
`;
不幸的是,它不起作用
感谢您提供的任何信息。对于返回单个对象的字段和返回对象列表的字段,指定选择集的方式没有区别——语法相同,即使响应的形状不同。使用graphiql,它会提示您。。。。查询看起来相同,响应的形状也不同