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
main
folder, move yourgraphql
folder into another package. Preferably one that matches the package where your java files reside. Something likecom.example.app.graphql
– makunomain
I've got:java\com\example\graphqlapollo\MainActivity
andgraphql\com\example\graphqlapollo
. It's probably correct. – yawConfiguration 'compile' is obsolete and has been replaced with 'implementation' and 'api'
- I didn't use compile in my gradle, I don't know from where that warning comes. – yawgraphql\com\example\graphqlapollo
insidemain
. This is where you need to put your.graphql
files, also yourschema.json
should be here. The new warning you are getting could be due to one of your dependencies usingcompile
instead ofapi
/implementation
. Im trying to build a project that would try to replicate your issue. – makuno