如何在第一次查询成功后使用 Apollo 客户端进行 GraphQL 惰性查询
How to make a GraphQL lazy query with Apollo client after the first query is successful
我正在尝试在初始查询成功后使用 Apollos useLazyQuery 挂钩查询 GQL 端点。我以为我可以通过检查第一个查询是否成功返回“数据”变量,然后在那里发出下一个请求来轻松地做到这一点,但是我收到了一个错误,这是我的代码:
const [getUserByUsername, { data, loading, error }] = useLazyQuery(GET_USER_BY_USERNAME);
const [getReachRelationship, {data, loading, error}] = useLazyQuery(GET_REACH_RELATIONSHIP);
这是我不断收到的错误 “无法重新声明块作用域变量”
问题是您要重新声明 data
loading
和 error
两次。
const [getUserByUsername, { data: user, loading: isUserLoading, error: isUserError }] = useLazyQuery(GET_USER_BY_USERNAME);
const [getReachRelationship, {data: reachRelationship, loading: isReachRelationshipLoading, error: isReachRelationshipError}] = useLazyQuery(GET_REACH_RELATIONSHIP);
console.log(user)
console.log(reachRelationship)
我正在尝试在初始查询成功后使用 Apollos useLazyQuery 挂钩查询 GQL 端点。我以为我可以通过检查第一个查询是否成功返回“数据”变量,然后在那里发出下一个请求来轻松地做到这一点,但是我收到了一个错误,这是我的代码:
const [getUserByUsername, { data, loading, error }] = useLazyQuery(GET_USER_BY_USERNAME);
const [getReachRelationship, {data, loading, error}] = useLazyQuery(GET_REACH_RELATIONSHIP);
这是我不断收到的错误 “无法重新声明块作用域变量”
问题是您要重新声明 data
loading
和 error
两次。
const [getUserByUsername, { data: user, loading: isUserLoading, error: isUserError }] = useLazyQuery(GET_USER_BY_USERNAME);
const [getReachRelationship, {data: reachRelationship, loading: isReachRelationshipLoading, error: isReachRelationshipError}] = useLazyQuery(GET_REACH_RELATIONSHIP);
console.log(user)
console.log(reachRelationship)