Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 具有新变量的Apollo Refetch查询组件_Reactjs_Variables_Apollo_Graphql Tag - Fatal编程技术网

Reactjs 具有新变量的Apollo Refetch查询组件

Reactjs 具有新变量的Apollo Refetch查询组件,reactjs,variables,apollo,graphql-tag,Reactjs,Variables,Apollo,Graphql Tag,我有一个Apollo查询组件,如下所示: <Query fetchPolicy='network-only' // also tried without and with 'no-cache' query={GET_MENUS} variables={{ foo // This has the default value of the state }} > {({ loading, error, data, refetch })

我有一个Apollo查询组件,如下所示:

<Query
    fetchPolicy='network-only' // also tried without and with 'no-cache'
    query={GET_MENUS}
    variables={{
        foo // This has the default value of the state
    }}
>
    {({ loading, error, data, refetch }) => {

      // Display Data here

      // We have an Imput here that can change the State of Bar in the parent Component
      <Button
          onPress={() => {
              /*refetch({
                  foo: { bar}
              }); */
              setBar(blubb); // I am using react hooks (useState)
          }}
          text='Refresh!'
      />
      }
    )}
</Query>

我在Apollo 3.0中使用变量重新蚀刻的解决方案:

import { gql, useApolloClient } from "@apollo/client";

const client = useApolloClient();

const SEARCH_PROJECTS = gql``

await client.query({
          query: SEARCH_PROJECTS,
          variables: { page: 1, limit: 1 },
          notifyOnNetworkStatusChange: true,
          fetchPolicy: "network-only"
})
请参阅有关获取策略和的详细信息

我的上下文如下:我获取项目列表,然后用户可以删除或更新项目。项目列表、项目、更新和删除是不同的组件。Apollo提供的默认刷新不允许我发送用于项目分页的变量,因此当我删除或更新项目时,我会手动刷新它,而无需创建一个结构,在该结构中我可以使用组件“项目列表”中的刷新或获取更多选项


听起来像是缓存问题。您能否编辑您的问题以显示
获取菜单的值
?谢谢您的回答!我更新了问题。对于那些想知道的人。阿波罗在那里没有虫子。这是我的错,因为我在查询组件中有另一个过滤函数,其中有条件
if(prepping&!loading)
,我忘记的只是在重新蚀刻之前将prepping设置为true,一切正常。谢谢,对不起……:)
import { gql, useApolloClient } from "@apollo/client";

const client = useApolloClient();

const SEARCH_PROJECTS = gql``

await client.query({
          query: SEARCH_PROJECTS,
          variables: { page: 1, limit: 1 },
          notifyOnNetworkStatusChange: true,
          fetchPolicy: "network-only"
})