7
votes

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
2
In your main folder, move your graphql folder into another package. Preferably one that matches the package where your java files reside. Something like com.example.app.graphqlmakuno
In folder main I've got: java\com\example\graphqlapollo\MainActivity and graphql\com\example\graphqlapollo . It's probably correct.yaw
Okay, I done what you said, and there's more generated folders, but class still not generates. I also gets a new warning: Configuration '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.yaw
Lets focus on graphql\com\example\graphqlapollo inside main. This is where you need to put your .graphql files, also your schema.json should be here. The new warning you are getting could be due to one of your dependencies using compile instead of api/implementation. Im trying to build a project that would try to replicate your issue.makuno
Try following the official Apollo android guide. Seems like you are depending on a past version of the plugin. Find the docs here: github.com/apollographql/apollo-androidmakuno

2 Answers

5
votes

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.

2
votes

In Project structure(File -> Project Structure -> Project) change your Gradle plugin version to 3.3.2 and Gradle version to 4.10.1.

if it still didn't work, change the Gradle versions to the older.

Hope it will works. Worked the same for me.