Apollo-android: Generated *Query class does not have a .builder() method

Created on 22 Dec 2019  路  3Comments  路  Source: apollographql/apollo-android

Summary

On following the readme the generated Query class does not have a .builder() method.

I don't think this is a bug, more of a question on what did I missed?

Description

Steps to get there:

  • created a folder for graphql files: app/src/main/graphql/com/github
  • downloaded schema.json of the GitHub api using Apollo client download in the folder
  • created a graphql query file in the folder:
query LoginViewer {
  viewer {
    login
  }
}

(This is the helloworld of GitHub api - returns the user login string.)

  • extended both app and module gradle files as per readme
  • rebuild gradle (all green)
  • called ./gradlew generateApolloClasses (success, class class LoginViewerQuery : Query<LoginViewerQuery.Data, LoginViewerQuery.Data, Operation.Variables> generated)
  • in the Android app's main activity when using LoginViewerQuery.builder() the error is: Unresolved reference: builder

Version

1.2.2

Bug

Most helpful comment

My bad - seems builder is not provided when there are no variables to "build". Just had to instantiate the class for the ApolloClient().query() method.

All 3 comments

My bad - seems builder is not provided when there are no variables to "build". Just had to instantiate the class for the ApolloClient().query() method.

This should be shown more prominently in the README. I had just a single variable and even then you don't get a builder. Took me some time to find this issue. Maybe a small text should be added to the "Consuming Code"-Section so people don't get confused by the builder not being available.

The problem continues. After searching and trying I solved it!

// Replace:
apollo {
generateKotlinModels.set(true)
}

// With:
apollo {
generateModelBuilder = true
}

Was this page helpful?
0 / 5 - 0 ratings