2
static Future<QueryResult> updateOrderStatus({required dynamic input, required String status, required String orderId, required String buyerId}) {
    final client = GraphqlClient.getGraphQlClient();
    print(input);

    final MutationOptions options = MutationOptions(
      document: gql(OrderMutaions.updateOrderStatus),
      variables: {'input': input},
      update: (cache, result) {
        print(orderId);
        print(buyerId);
        final req = QueryOptions(
          document: gql(OrderQueries.getOrderByOrderId),
          variables: {
            'input': {"orderId": orderId, "buyerUid": buyerId},
          },
        ).asRequest;

        final response = cache.readQuery(req);

        print('cache response');
        print(response);

        response?["getOrderByOrderId"]["status"] = status;

        print('cache response new');
        print(response);

        if (response != null) {
          cache.writeQuery(
            req,
            broadcast: true,
            data: response,
          );
        }

        return cache;
      },
    );

    return client.mutate(options);
  }

我正在使用这个包在颤振中使用 graphql,因为我不想使用查询/变异小部件。我将 watchQuery 用于 getOrderByOrderId 并监听更改。当调用 updateOrderStatus 查询时,我会更新缓存,以便 watchQuery 获取更改。但是,当第一次状态更改时,它可以正常工作。缓存已更新,并且 watchquery 获取更改。但是,当下次再次更改状态时,cache.readQuery(req) 为给定查询返回空值。因此,这只工作一次。我不明白为什么第二次为空。错误在哪里?

4

0 回答 0