React native 使用GraphQL';s与阿波罗在react native中联合

React native 使用GraphQL';s与阿波罗在react native中联合,react-native,graphql,apollo,react-apollo,React Native,Graphql,Apollo,React Apollo,我目前正在react原生应用程序中使用react apollo,我面临一个问题 每当我尝试进行包含联合的查询时,它都会失败,引发以下网络错误: 网络错误:请求的值的键不是对象 我在React.js应用程序中使用了完全相同的代码,效果很好。GraphQL端点是我自己的服务器,使用PHP和Youshido捆绑包开发 以下是片段声明部分: const httpLink = new HttpLink({uri: 'http://10.1.68.64:8000/graphql'}); const fra

我目前正在react原生应用程序中使用react apollo,我面临一个问题

每当我尝试进行包含联合的查询时,它都会失败,引发以下网络错误:

网络错误:请求的值的键不是对象

我在React.js应用程序中使用了完全相同的代码,效果很好。GraphQL端点是我自己的服务器,使用PHP和Youshido捆绑包开发

以下是片段声明部分:

const httpLink = new HttpLink({uri: 'http://10.1.68.64:8000/graphql'});

const fragmentMatcher = new IntrospectionFragmentMatcher({
    introspectionQueryResultData: {
      __schema: {
        types: [
          {
            "kind": "UNION",
            "name": "QuestionUnion",
            "possibleTypes": [
              {
                "name": "QuestionUnionTypeA"
              },
              {
                "name": "QuestionUnionTypeB"
              },
              {
                "name": "QuestionUnionTypeC"
              }
            ]
          },
        ],
      },
    }
});

const cache = new InMemoryCache({ fragmentMatcher });

const client = new ApolloClient({
    link: httpLink,
    cache: cache,
});
Screen.js文件中的查询(与React.js和React native中的查询完全相同):

在同一Screen.js文件中使用查询的部件:

const resultDisplayer = ({ data }) => {
    if(data.error){
        return <Text> {JSON.stringify(data)} </Text>;
    }
    if(data.loading){
        return <Spinner/>;
    }
    else {
        return <Text> Ok </Text>;
    }
};

const query = graphql(FindForm, {
    options: {
        variables: {
            id: this.state.id,
        }
    }
})(resultDisplayer);
constresultdisplayer=({data})=>{
if(data.error){
返回{JSON.stringify(data)};
}
if(数据加载){
返回;
}
否则{
返回Ok;
}
};
const query=graphql(FindForm{
选项:{
变量:{
id:this.state.id,
}
}
})(结果显示);
令人不安的是,在少数情况下不会抛出错误:

  • 当我远程调试应用程序时
  • 当查询不包含联合部件时
  • 当union部件没有返回的内容时(如果没有问题UNIONTYPE A、B和C的实例)

因此,我想我做错了什么,但我似乎找不到哪里弄错了。如果你们有任何想法,我愿意尝试任何方法。

你们找到解决方案了吗?我也有类似的问题。一切正常在标准react dom中运行查询,或在react native中进行远程调试,然后只要我在设备上,我就会收到与您看到的相同的错误。我只在android(emulator&device)上收到此错误,一切正常ios@BaronVonKaneHoffen很抱歉,回复太晚了,我无法找到解决方案,在没有工会的情况下继续前进。然而,如果你发现了什么,我真的很想知道你是怎么做到的,因为改变我所有的后端逻辑是很耗时的,而且有点复杂heartbreaking@R.Duteil哈,我最终完全放弃了阿波罗,转而使用Firebase/Firestore。我花了两天的时间才在一个月内完成阿波罗+AWS AppSync/Lambda/DynamoDB等项目。很棒的文档+非常简单。我想这要看你在做什么。
const resultDisplayer = ({ data }) => {
    if(data.error){
        return <Text> {JSON.stringify(data)} </Text>;
    }
    if(data.loading){
        return <Spinner/>;
    }
    else {
        return <Text> Ok </Text>;
    }
};

const query = graphql(FindForm, {
    options: {
        variables: {
            id: this.state.id,
        }
    }
})(resultDisplayer);