question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

.graphql file isn't being detected

See original GitHub issue

I followed the Getting Started guide to try this but the only way to get a response is to pass a QueryContainer reading the .graphql file instead of passing the builder with the @GraphQuery annotation

I checked the demo app and it’s done the ‘same’ way the guide says. Tried moving GetMarketplaceListing.graphql to another dir and still worked. Renaming the file made stopped working.

This was tested on AVD API 30 and on a Redmi Note 5 Android 10.

NOT Working MainActivity:

val query = QueryContainerBuilder().putVariable("idMal", 40060)
val anime = apiService.get(query)

ApiService (interface):

@POST("/graphql")
@GraphQuery("GetAnime")
suspend fun get(@Body builder: QueryContainerBuilder): Response<GraphContainer<Data>>

Body is null and the errorBody is ‘Must provide query string’

Working MainActivity:

val query = QueryContainerBuilder().setQuery(assets.open("graphql/queries/GetAnime.graphql").bufferedReader().readText())
.putVariable("idMal", 40060).build()
val anime = apiService.get(query)

ApiService (interface):

@POST("/graphql")
suspend fun get(@Body builder: QueryContainer): Response<GraphContainer<Data>>

This way the request is done fine and I get the data that I want.

GetAnime.graphql

query GetAnime($idMal: Int) {
    anime(idMal: $idMal) {
        id
        idMal
        idAl
    }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
LetrixZcommented, Apr 1, 2021

It worked! Thanks 😃

1reaction
wax911commented, Apr 1, 2021

I think I found your problem, in provideApiService

    .addConverterFactory(GraphConverter.create(context, ILogger.Level.VERBOSE))
    .addConverterFactory(GsonConverterFactory.create(GsonBuilder().create()))

Swap the order of graph converter and gson converter, otherwise retrofit will default to the Gson and you should see more loggs

2021-04-01 12:02:32.146 9534-9534/com.letrix.miranime V/GraphProcessor: main: has obtained a synchronized lock on the object
2021-04-01 12:02:32.146 9534-9534/com.letrix.miranime V/GraphProcessor: main: is initializing query files
2021-04-01 12:02:32.154 9534-9534/com.letrix.miranime V/GraphProcessor: main: has completed initializing all graphql files
2021-04-01 12:02:32.154 9534-9534/com.letrix.miranime V/GraphProcessor: main: discovered `3` graphql files
2021-04-01 12:02:32.250 9534-9569/com.letrix.miranime D/GraphProcessor: Looking up `.graphql` file matching: GetHome.graphql

N.B GraphConverter has factory methods to initialise everything you need e.g. GraphConverter.create(context, ILogger.Level.VERBOSE)

If you need GsonConverterFactory for some other endpoints you could simply extend GraphConverter and override requestBodyConverter to provide a different converter for anything else that is not annotated with GraphQuery on the methodAnnotations

Read more comments on GitHub >

github_iconTop Results From Across the Web

in path causes .graphql files not to be found #6174 - GitHub
If an & character is the a parent directory that codegen is running in it will produce the error Unable to find any...
Read more >
schema.graphql file can't be found (node graphql-yoga)
You gave the path ./schema.graphql which makes node look for the file in the directory where you run it instead of the correct...
Read more >
Apollo extension for VS Code - Apollo GraphQL Docs
The Apollo VS Code extension provides an all-in-one tooling experience for developing apps with Apollo. Using jump to definition on a fragment.
Read more >
GraphQL Code Libraries, Tools and Services
A query language for your API — GraphQL provides a complete description of the data in your API, gives clients the power to...
Read more >
Five Common Problems in GraphQL Apps (And How to Fix ...
Namely, you need one schema for your database, and another one for your GraphQL endpoint. Not only is it frustrating to have to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found