[feature/chucker-gql] GQL support against latest develop #800
Conversation
MiSikora
left a comment
There was a problem hiding this comment.
For a PR that introduces integration with a new specification, there are no tests. Please cover necessary scenarios such as GET and POST requests with ChuckerInterceptor as both application and network interceptor.
It would be also helpful if you could follow our PR template. Screenshots especially would be appreciated.
| Status.Failed -> " ! ! ! $method $path" | ||
| Status.Requested -> " . . . $method $path" | ||
| else -> "$responseCode $method $path" | ||
| else -> "$responseCode $method $path ${isGraphqlRequest.takeIf { true } ?: ""}" |
| gqlVisibiltyGroup.visibility = if (transaction.isGqlRequest) { | ||
| transaction.gqlOperationName?.let { opName -> | ||
| setGqlInfo( | ||
| operationName = opName, | ||
| ProtocolResources.Gql() | ||
| ) | ||
| View.VISIBLE | ||
| } ?: View.GONE | ||
| } else View.GONE |
There was a problem hiding this comment.
For a piece of code that deals with visibility, It is very hard to understand what is going on here. Please refactor it.
| val countriesQuery = "query countries {\n" + | ||
| " countries {\n" + | ||
| " name\n" + | ||
| " }\n" + | ||
| "}\n" |
There was a problem hiding this comment.
Please use raw strings. Preferably trimMargin() variant.
|
|
||
| internal interface GraphQLSWApi { | ||
| @POST("/") | ||
| @Headers("Content-Type: application/json") |
There was a problem hiding this comment.
Is it necessary? GsonConverterFactory should add this header on its own.
| internal interface GraphQLSWApi { | ||
| @POST("/") | ||
| @Headers("Content-Type: application/json") | ||
| fun getCountries(@Body body: GraphQLResponseBody?): Call<Any?> |
There was a problem hiding this comment.
The body doesn't have to be nullable.
| } else { | ||
| decodedContent?.let { content -> | ||
| transaction.gqlOperationName = inferGqlRequest(content) | ||
| } |
There was a problem hiding this comment.
I don't think it is correct to have it in the else clause here. It indicates that having the GraphQL operation name is somehow related to reaching the request threshold.
| ) | ||
|
|
||
| internal interface GraphQLSWApi { | ||
| @POST("/") |
There was a problem hiding this comment.
I would like to have an example of a GET request if possible.
| client: OkHttpClient, | ||
| ) : HttpTask { | ||
|
|
||
| private val api = Retrofit.Builder() |
There was a problem hiding this comment.
I think that the vast majority of people will use GraphQL with something like Apollo. I would prefer to see a real-life scenario integration within our sample instead of Retrofit.
| } | ||
| }.firstOrNull() | ||
|
|
||
| private fun inferGqlRequest(body: String): String? { |
There was a problem hiding this comment.
Inferring GraphQL from a body won't work for GET requests as there is only URL query parameter for those.
It's a bit hard to have a full-proof solution as anyone could have query parameters or bodies that conform to GraphQL format. I have an idea of how to deal with it but let's just first implement handling of GET requests as well.
| val isGraphqlRequest: Boolean | ||
| get() = !gqlOperationName.isNullOrEmpty() |
I experienced it in the past as well but I thought that #750 fixed it. |
I'm retracting my review because I don't know how GH behaves after I remove myself from maintainers, and I don't want to lock this PR
|
Sorry for the late reply here. |
|
Please close this PR in respect of a better implementation at https://github.com/ChuckerTeam/chucker/pull/805 |
👍 We'll keep the disucssion going on #805 |
There was already an old implementation done here . This PR seems to be old one (2019) and way out of sync with develop branch. I have refactored it to meet the latest changes.
This almost getting ready and not the final PR yet, need to get valuable input on the code quality and optimization if required.
Sample Activity has also been provided for the demo
Known Issues
Couldn't successfully run the sample until i commented this part of the code