问题描述
我正在尝试使用 Apollo 代码生成将 Android 应用程序与 GraphQL 连接起来.我收到了这种类型的错误:
ERROR: Value 'main GraphQL source' specified for property '$1' cannot be converted to a file.
我在 medium 上制作了很多教程,使用了 github 指令,但没有一个对我没有帮助.为了生成 schema.json,我使用了 apollo,也弃用了 apollo-codegen.
项目级 gradle 依赖项:
dependencies { classpath 'com.android.tools.build:gradle:3.4.0' classpath 'com.apollographql.apollo:gradle-plugin:0.4.1' }
在 app-gradle 上我添加了一行:
apply plugin: 'com.apollographql.android'
我还在主文件夹中创建了一个文件夹"graphql",并将 getPosts.graphql 文件放入:
query allPostsQuery{ findAllUsers{ username email } }
然后我使用(我的查询的一部分)生成 schema.json:
{ "kind": "OBJECT", "name": "Query", "description": "", "fields": [ { "name": "findAllUsers", "description": "", "args": [], "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "LIST", "name": null, "ofType": { "kind": "OBJECT", "name": "User", "ofType": null } } }, "isDeprecated": false, "deprecationReason": null }, { "name": "findUser", "description": "", "args": [ { "name": "username", "description": "", "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "SCALAR", "name": "String", "ofType": null } }, "defaultValue": null } ], "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "OBJECT", "name": "User", "ofType": null } }, "isDeprecated": false, "deprecationReason": null } ], "inputFields": null, "interfaces": [], "enumValues": null, "possibleTypes": null },
架构生成:
apollo-codegen introspect-schema http://localhost:1100/graphql --output schema.json
推荐答案
我尝试了 Sneha 的建议,对我来说效果很好.
如果你不想降级Android Gradle plugin和Gradle版本你可以改变
classpath 'com.apollographql.apollo:gradle-plugin:0.4.1'
到
classpath 'com.apollographql.apollo:apollo-gradle-plugin:1.0.0'
在您的项目级 build.gradle 文件中.
另外,请将 apollo-runtime 和 apollo android support library 更新到您的 app 模块的 build.gradle 文件中的最新版本.
implementation 'com.apollographql.apollo:apollo-runtime:1.0.0' implementation "com.apollographql.apollo:apollo-android-support:1.0.0"
希望这能解决您的问题,如果您还有任何问题,请告诉我.
问题描述
I'm trying to connect Android app with GraphQL using Apollo code generation. I'm getting this type of error:
ERROR: Value 'main GraphQL source' specified for property '$1' cannot be converted to a file.
I made lot of tutorials on medium, used github instructions but none of them didn't help me. To generate schema.json I used apollo and also deprecated apollo-codegen.
Project-level gradle dependecies:
dependencies { classpath 'com.android.tools.build:gradle:3.4.0' classpath 'com.apollographql.apollo:gradle-plugin:0.4.1' }
On app-gradle I added one line:
apply plugin: 'com.apollographql.android'
I also created a folder 'graphql' in my main folder, and I put getPosts.graphql file:
query allPostsQuery{ findAllUsers{ username email } }
Then I'm generated schema.json using (a part with my query):
{ "kind": "OBJECT", "name": "Query", "description": "", "fields": [ { "name": "findAllUsers", "description": "", "args": [], "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "LIST", "name": null, "ofType": { "kind": "OBJECT", "name": "User", "ofType": null } } }, "isDeprecated": false, "deprecationReason": null }, { "name": "findUser", "description": "", "args": [ { "name": "username", "description": "", "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "SCALAR", "name": "String", "ofType": null } }, "defaultValue": null } ], "type": { "kind": "NON_NULL", "name": null, "ofType": { "kind": "OBJECT", "name": "User", "ofType": null } }, "isDeprecated": false, "deprecationReason": null } ], "inputFields": null, "interfaces": [], "enumValues": null, "possibleTypes": null },
Schema-generation:
apollo-codegen introspect-schema http://localhost:1100/graphql --output schema.json
推荐答案
I tried what Sneha suggested, that's working fine for me.
If you don't want to downgrade Android Gradle plugin and Gradle version you can change
classpath 'com.apollographql.apollo:gradle-plugin:0.4.1'
to
classpath 'com.apollographql.apollo:apollo-gradle-plugin:1.0.0'
in your project level build.gradle file.
Also please update apollo-runtime and apollo android support library to latest version in your build.gradle file of app module.
implementation 'com.apollographql.apollo:apollo-runtime:1.0.0' implementation "com.apollographql.apollo:apollo-android-support:1.0.0"
Hopefully this will resolve your issue, let me know if you've any issue further.