apollo/graphql/react 中的重新获取查询期间如何将 Id 传递给未在组件中调用的查询
How to pass an Id to a query that is not being called in the component during refetchQuery in apollo/graphql/react
我正在尝试获取需要将 id
传递给它的查询。但是我没有在组件中调用查询。我尝试使用 options
在导出中传递它,但无法正常工作。
这是我的:
this.props
.addLyricToSong({
variables: {
content: this.state.content,
songId: this.props.songId
},
refetchQueries: [{query: fetchSong}]
});
正如我所说,我得到的错误是查询 fetchSong
需要将 id
传递给它。
我在底部试过这个:
options: props => {
return { variables: { id: props.songId } };
}
但正如我所说,我没有在组件中调用此查询,我认为这就是它不起作用的原因。
As outlined in the docs,作为传递给 refetchQueries
的数组一部分的每个对象应包含两个属性:
query: Query is a required property that accepts a GraphQL query
created with graphql-tag’s gql template string tag. It should contain
a single GraphQL query operation that will be executed once the
mutation has completed.
[variables]: Is an optional object of
variables that is required when query accepts some variables.
因此,如果您的 fetchSong
查询需要任何变量,您也需要传入这些变量:
refetchQueries: [{query: fetchSong, variables: { id: 'someID' }}]
我正在尝试获取需要将 id
传递给它的查询。但是我没有在组件中调用查询。我尝试使用 options
在导出中传递它,但无法正常工作。
这是我的:
this.props
.addLyricToSong({
variables: {
content: this.state.content,
songId: this.props.songId
},
refetchQueries: [{query: fetchSong}]
});
正如我所说,我得到的错误是查询 fetchSong
需要将 id
传递给它。
我在底部试过这个:
options: props => {
return { variables: { id: props.songId } };
}
但正如我所说,我没有在组件中调用此查询,我认为这就是它不起作用的原因。
As outlined in the docs,作为传递给 refetchQueries
的数组一部分的每个对象应包含两个属性:
query: Query is a required property that accepts a GraphQL query created with graphql-tag’s gql template string tag. It should contain a single GraphQL query operation that will be executed once the mutation has completed.
[variables]: Is an optional object of variables that is required when query accepts some variables.
因此,如果您的 fetchSong
查询需要任何变量,您也需要传入这些变量:
refetchQueries: [{query: fetchSong, variables: { id: 'someID' }}]