如何从json文件运行graphql查询
[我刚刚开始学习android中的GraphQl api。我现在面临的问题是,我不知道该api的工作方式。我从下面的链接-:
要求下载您的api的模式文件的地方。
通过任何方式,我都可以在任何类型的控制台中运行schema.json文件,通过该控制台,我可以理解这将如何工作以获取正确的数据。
谢谢
这里是下面的代码,iam正在使用-
val BASE_URL=""
fun getClient(): ApolloClient {
val okHttp = OkHttpClient
.Builder()
.addInterceptor({ chain ->
val original = chain.request()
val builder = original.newBuilder().method(original.method(),
original.body())
builder.addHeader("Authorization"
, "Bearer " + "bac8dc6fd2119fcdbe94332c3e1aa2c43f897b24")
chain.proceed(builder.build())
})
.build()
return ApolloClient.builder()
.serverUrl(BASE_URL)
.okHttpClient(okHttp)
.build()
}
}
以及用于致电服务...
progress_bar.visibility = View.VISIBLE
client.getClient().query(FindQuery
.builder()
.name(repo_name_edittext.text.toString())
.owner(owner_name_edittext.text.toString())
.build())
.enqueue(object : ApolloCall.Callback<FindQuery.Data>() {
override fun onFailure(e: ApolloException) {
Log.d("exception ",e.message.toString())
progress_bar.visibility = View.GONE
}
override fun onResponse(response: Response<FindQuery.Data>) {
Log.d(" " + response.data()?.repository(),"")
runOnUiThread {
progress_bar.visibility = View.GONE
name_text_view.text = String.format(getString(R.string.name_text),
response.data()?.repository()?.name())
description_text_view.text = String.format(getString(R.string.description_text),
response.data()?.repository()?.description())
forks_text_view.text = String.format(getString(R.string.fork_count_text),
response.data()?.repository()?.forkCount().toString())
url_text_view.text = String.format(getString(R.string.url_count_text),
response.data()?.repository()?.url().toString())
}
}
})
}
}
Graphql文件已使用-:
user(login: $login) {
repositories(first:20){
nodes{
id
name
}
}
}
}
成绩文件
implementation 'com.apollographql.apollo:apollo-runtime:1.2.0'
implementation "com.apollographql.apollo:apollo-android-support:1.2.0"
回答如下:您需要为Android安装graphql代码生成器,因为在您的帖子中,我看不到您在哪里或实际上配置了生成器。 Tutorial for the code generation setup on android。
只需按照本教程进行操作,如果您不清楚它,您总是可以签出使用相同技术的Angular或React教程,以了解它。
如何从json文件运行graphql查询
[我刚刚开始学习android中的GraphQl api。我现在面临的问题是,我不知道该api的工作方式。我从下面的链接-:
要求下载您的api的模式文件的地方。
通过任何方式,我都可以在任何类型的控制台中运行schema.json文件,通过该控制台,我可以理解这将如何工作以获取正确的数据。
谢谢
这里是下面的代码,iam正在使用-
val BASE_URL=""
fun getClient(): ApolloClient {
val okHttp = OkHttpClient
.Builder()
.addInterceptor({ chain ->
val original = chain.request()
val builder = original.newBuilder().method(original.method(),
original.body())
builder.addHeader("Authorization"
, "Bearer " + "bac8dc6fd2119fcdbe94332c3e1aa2c43f897b24")
chain.proceed(builder.build())
})
.build()
return ApolloClient.builder()
.serverUrl(BASE_URL)
.okHttpClient(okHttp)
.build()
}
}
以及用于致电服务...
progress_bar.visibility = View.VISIBLE
client.getClient().query(FindQuery
.builder()
.name(repo_name_edittext.text.toString())
.owner(owner_name_edittext.text.toString())
.build())
.enqueue(object : ApolloCall.Callback<FindQuery.Data>() {
override fun onFailure(e: ApolloException) {
Log.d("exception ",e.message.toString())
progress_bar.visibility = View.GONE
}
override fun onResponse(response: Response<FindQuery.Data>) {
Log.d(" " + response.data()?.repository(),"")
runOnUiThread {
progress_bar.visibility = View.GONE
name_text_view.text = String.format(getString(R.string.name_text),
response.data()?.repository()?.name())
description_text_view.text = String.format(getString(R.string.description_text),
response.data()?.repository()?.description())
forks_text_view.text = String.format(getString(R.string.fork_count_text),
response.data()?.repository()?.forkCount().toString())
url_text_view.text = String.format(getString(R.string.url_count_text),
response.data()?.repository()?.url().toString())
}
}
})
}
}
Graphql文件已使用-:
user(login: $login) {
repositories(first:20){
nodes{
id
name
}
}
}
}
成绩文件
implementation 'com.apollographql.apollo:apollo-runtime:1.2.0'
implementation "com.apollographql.apollo:apollo-android-support:1.2.0"
回答如下:您需要为Android安装graphql代码生成器,因为在您的帖子中,我看不到您在哪里或实际上配置了生成器。 Tutorial for the code generation setup on android。
只需按照本教程进行操作,如果您不清楚它,您总是可以签出使用相同技术的Angular或React教程,以了解它。