当我尝试执行两个不同的查询时,我会收到此错误,如何解决?
``错误:需要查询选项。您必须在查询选项中指定GraphQL文档。
这是代码的片段
//in my index class I dispatch some actions
componentDidMount () {
this.props.fetchNavigationBarDataThunk();
this.props.fetchActionToDoTitleDataThunk();
}
//then in my action I have something like that
import ApolloClient, { createNetworkInterface } from 'apollo-client';
import gql from 'graphql-tag';
const opts = {uri: 'http://localhost:8080/wfgen/graphql'};
const networkInterface = createNetworkInterface(opts);
const client = new ApolloClient({networkInterface});
var query1 = gql`query {...}`;
var query2= gql`query {...}`;
export function fetchActionToDoTitleDataThunk () {
return (dispatch) => {
dispatch(fetchActionToDoTitleData())
client.query({ query2 }).then((results) => {
if (results.networkStatus === 7 && results.loading === false) {
dispatch(fetchActionToDoTitleDataFulFilled(results));
}
else{
...
export function fetchNavigationBarDataThunk () {
return (dispatch) => {
dispatch(fetchNavigationBarData())
client.query({query}).then((results) => {
if (results.networkStatus === 7 && results.loading === false) {
dispatch(fetchNavigationBarDataFulFilled(results));
}
else{
....
答案 0 :(得分:1)
我认为您的问题是client.query({ query2 })
和client.query({query})
首先,使用速记对象属性初始化,{ query2 }
等同于{ query2: query2 }
- 但ApolloClient需要类似{ query: query2 }
的内容。
第二,根据您提供的代码,query
未定义。我认为您的意思是client.query({query: query1})
或client.query({query: query2})