如何在 Android 中发送带有片段的 graphql 查询

How to send graphql query with fragments in Android

我是 graphql 的新手,我需要帮助来为我的 android 应用发送带有片段的 graphql 查询。 以下是网络接受的查询格式。

query{
  user(ident:"JohnDoe"){
    myStory{
      description,
    placements(first:3){
      edges{
        node{
          mediaItemType
          mediaItem {
            ...VideoFragment
            ...PhotoFragment
          }
        }
      }
    }
    }
  }
}
fragment VideoFragment on Video {
    videoHTML
}
fragment PhotoFragment on Photo {
    url(size:10)
}

感谢任何帮助!!

这可能取决于 GraphQL 的服务器实现。 GraphQL 没有定义媒介,这使得这个问题有些宽泛。自 express-graphql is so common, I'll make a guess that you may be using that. If that's true, you can query it over HTTP with more details outlined on the documentation for that project。如果情况并非如此,您将需要进行更多挖掘。

我通过将其添加到 strings.xml 中来使其正常工作,如下所示。确保没有多余的空格。

<string name="graphiql_detail_search">
{
  user(ident: "JohnDoe") {
    myStory {
      description
      placements(first: 3) {
        edges {
          node {
            mediaItemType
            mediaItem {
              ...VideoFragment
              ...PhotoFragment
            }
          }
        }
      }
    }
  }
}

fragment VideoFragment on Video {
  videoHTML
}

fragment PhotoFragment on Photo {
  url(size: 10)
}