小编ski*_*130的帖子

Apollo 客户端无法连接到 GraphQL 服务器(http 调用无法执行)

我正在尝试设置一个简单的 Android 应用程序,该应用程序通过使用 Java GraphQL 的 Springboot 应用程序连接到我本地主机上设置的 GraphQL 服务器。使用 GraphiQL 我可以很好地查询。问题是当我尝试使用 Apollo Client 在我的应用程序中进行相同的查询时,我收到以下错误

 

“com.apollographql.apollo.exception.ApolloNetworkException:无法执行http调用”

 

我使用本教程通过 Springboot 设置 GraphQL 服务器并定义 GraphQL 模式。我依靠本教程来帮助设置应用程序。

早些时候我曾尝试通过我的网络浏览器访问服务器,但我会收到一条错误消息

 

“出现意外错误(类型=错误请求,状态=400)。所需的字符串参数‘查询’不存在”

 

所以我尝试了 Postman 并将在 GraphiQL 中工作的相同查询发送到本地主机并得到一个错误返回。这是使用 GET 请求完成的,所以我尝试了 POST 并且它像在 GraphiQL 中一样工作得很好。所以我认为由于某种原因,我通过 Springboot 设置的 GraphQL 服务器不能处理 GET 请求。我不知道这是因为我在设置时搞砸了一些东西,或者这就是 GraphQL 处理查询的方式,但如果有人能就此启发我,我将不胜感激。

 

无论如何,我设置了一个断点并逐步执行该应用程序,发现 Apollo 也通过 GET 请求发送查询,我假设这是此问题的根源。我犯了一个错误并误读了代码,我了解到它绝对不是发送 GET 请求,但问题仍然存在,我不知道为什么。

这是主要活动

private static final String BASE_URL = 
    "http://xxx.xxx.xxx.xxx:8080/graphql";
    private static final String TAG = "MainActivity";
    private TextView textBox;
    private Button queryButton;

    @Override
    protected …
Run Code Online (Sandbox Code Playgroud)

java android-studio graphql apollo-client graphql-java

5
推荐指数
1
解决办法
3618
查看次数

使用 Android 导航组件的深层链接打开错误屏幕

嗨,我正在学习如何使用 Android 的导航组件,作为其中的一部分,我正在制作一个非常基本的练习应用程序来尝试一些东西。我已经设置了两个屏幕之间的基本导航和数据传输,但我坚持的部分是设置深层链接。目前,我已将深层链接标签放置在当前无法通过任何其他方式到达的目的地(片段)中。这基本上是与其他两个连接的屏幕分开的第三个屏幕,深层链接是访问它的唯一途径。

我在下面分享了我的导航 xml 文件以及我的清单。

这是导航文件,相关位是最后一个片段标签,创造性地命名为“firstDeepLinkFragment”。


<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/navigation_graph"
    app:startDestination="@id/firstFragment">

    <fragment
        android:id="@+id/firstFragment"
        android:name="android.bignerdranch.navcontrollertest.FirstFragment"
        android:label="navigation_first_fragment"
        tools:layout="@layout/navigation_first_fragment" >
        <action
            android:id="@+id/action_firstFragment_to_secondFragment"
            app:destination="@id/secondFragment"
            app:enterAnim="@anim/nav_default_enter_anim"/>
    </fragment>

    <fragment
        android:id="@+id/secondFragment"
        android:name="android.bignerdranch.navcontrollertest.SecondFragment"
        android:label="navigation_second_fragment"
        tools:layout="@layout/navigation_second_fragment" />

    <fragment
        android:id="@+id/firstDeepLinkFragment"
        android:name="android.bignerdranch.navcontrollertest.FirstDeepLinkFragment"
        android:label="first_deeplink_fragment"
        tools:layout="@layout/first_deeplink_fragment" >
        <deepLink
            android:id="@+id/deepLink"
            app:uri="example://gizmos" />
    </fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)

 

这是清单。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.bignerdranch.navcontrollertest">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <nav-graph android:value="@navigation/navigation_graph"/>


        </activity>
    </application>

</manifest>
Run Code Online (Sandbox Code Playgroud)

 

所以根据我对导航组件下深层链接如何工作的理解,我所要做的就是将深层链接标签添加到我想要链接的目的地,建立 URI 作为该标签的属性,然后添加导航 -清单中的图形标记并将其指向正确的导航图形文件。如果我正确设置了这些东西,我应该有一个适当的深层链接设置并且一切顺利。问题是,当我输入以下命令来测试深层链接时,adb shell …

android android-intent android-architecture-navigation

4
推荐指数
1
解决办法
2985
查看次数