Apollo的使用似乎根本没有执行,我该如何打开调试语句或Apollo Client的内容?
我使用apolloprovider
根据文档配置了Apollo客户端,以便我可以在嵌套组件中使用useQuery
。当我使用apolloclient
提供的查询时,该查询提供给apolloprovider
,即:
apolloClient.query({query, variables});
查询工作正常。但是,在树下的屏幕上,我有以下内容:
export default function SomeScreen({ route }: RouteProps) {
...
let query: DocumentNode;
switch (route.params.someParam) {
case 'A':
query = someQuery1;
break;
...
default:
query = someQueryX;
}
const {loading, error, data} = useQuery<{myData: SomeType[]}, QueryArgTypes>(
query,
{variables}, //assigned elsewhere but they're constant
);
if (loading) return <Text>Loading</Text>
if (error) return <Text>Error</Text>
return (
<FlatList
data={data?.myData}
renderItem={({ item }) => (<SomeComp elem={item} />)}
keyExtractor={(item) => (
item._id!.toString()
)}
/>
);
}
但是,在这种情况下,如果(加载)分支始终是正确的。此外,实例化apolloclient
是我正在从事的项目的一部分时,我使用的uri
是。当我的Query
执行时,我能够将其设置为暂停执行,并且根本无法达到我设置的任何断点。因此,据我所知,usequery
甚至都不试图执行查询(从不到后端),但我没有对正在发生的事情进行任何描述。有人知道会发生什么吗?一些相关的依赖性是:
"react": "17.0.1",
"react-native": "0.64.3",
"@apollo/client": "^3.6.2",
I have the Apollo client configured as per the docs, using the ApolloProvider
so that I may be able to use useQuery
in nested components. When I run queries using the apolloClient
that is provided to the ApolloProvider
, I.e.:
apolloClient.query({query, variables});
queries work just fine. However, in a screen further down the tree I have something like the following:
export default function SomeScreen({ route }: RouteProps) {
...
let query: DocumentNode;
switch (route.params.someParam) {
case 'A':
query = someQuery1;
break;
...
default:
query = someQueryX;
}
const {loading, error, data} = useQuery<{myData: SomeType[]}, QueryArgTypes>(
query,
{variables}, //assigned elsewhere but they're constant
);
if (loading) return <Text>Loading</Text>
if (error) return <Text>Error</Text>
return (
<FlatList
data={data?.myData}
renderItem={({ item }) => (<SomeComp elem={item} />)}
keyExtractor={(item) => (
item._id!.toString()
)}
/>
);
}
However, in this case, the if (loading)
branch is just always true. Furthermore, the uri
I used when instantiating apolloClient
is one which is part of the project I'm working on. I was able to set break points in it to pause execution when my query
executes, and it never reaches any of the breakpoints I've set at all. So as far as I can tell, useQuery
isn't even trying to execute the query (never makes it to the backend) but I don't get any description of what's going on. Anyone have any idea what might be happening? Some relevant dependencies are:
"react": "17.0.1",
"react-native": "0.64.3",
"@apollo/client": "^3.6.2",
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
老实说,我不知道这个问题可能是什么,但是以下是一个示例,因此您可以确保客户的适当设置:
client.js
app.tsx
儿童组件:
Honestly I don't know what that issue might be, but here's an example so you can make sure you have the proper set up of the client:
client.js
App.tsx
Child component:
显然这是一个已知的错误。如果其他任何人都遇到这一点,升级到Beta为我解决了问题:
'loading'在用“ usequery”加载数据时,使用'apolloclient'在react-native 中仍然是正确的
Apparently this was a known bug. In case anyone else encounters this, upgrading to the beta solved it for me:
'loading' remains true when loading data with 'useQuery' using 'apolloClient' in react-native