Have a question about debugging query hash mismatc...
# apollo-kotlin
s
Have a question about debugging query hash mismatches. I keep registering my client queries to be safe listed operations but when my client makes the call, they are getting treated as forbidden / 400 response. Tried updating to latest 3.1.0 , but so far no luck. According to our graphql platform team the iOS faced similar difficulties before upgrading their apollo codegen library, but android doesn't seem to have a separate codegen library, thanks in advance, been trying to get data back for my query in app but it only works in playground for a few weeks.🤕
K 1
b
Hi! To be sure, are you using the Gradle task to do the registration?
🙏 1
s
No i don't have Apollo key, so i am using a homemade npm cli tool which wraps over the Apollo command line interface i believe
Our graphql team suggested to use this cli tool, long-term would like to look into setting up the Gradle task
Do you think the Gradle codegen version might produce different results from cli version?
b
That is probably the issue because the hashing used to create the operation id is done on the exact (or almost exact, if I remember correctly 😛) query. Since the Apollo Kotlin codegen sometimes manipulates your query text (e.g. to add
__typename
), they may differ.
1
🙏 1
K 1
s
Big thanks 💗, also i may try preemptively adding __typename lol, at this point just having more stuff to try and troubleshoot is a godsend!
👍 1
b
maybe this option can also help you: it outputs in a single json file all the operation texts they are sent by the client
w
i may try preemptively adding __typename lol
In 3.x not every type has
__typename
though. What I tend to do is open the relevant
SomeOperationQuery
generated file, copy the entire string from
QUERY_DOCUMENT
(including
trimMargin()
but not including
QueryDocumentMinifier.minify
) and run
Copy code
pbpaste | kotlinc-jvm | tail -n +3 | sed '$d' | sed 's/^.*kotlin.String = //g' | pbcopy
in the terminal. That will run the code as a Kotlin script, do some string magic to only get the output and copy it back to the clibpoard. Very useful, although that’s for mac obviously. You can also get the
QUERY_DOCUMENT
string and run it in a Kotlin scratch file in Android Studio and copy the output
mind blown 3
today i learned 2
🙏 1
e
generateOperationOutput should be exactly what you want to register with, as it matches what Apollo will be sending after inlining fragments and minimizing etc.
🙌 1
s
adding
__typename
field did the trick after all in this instance 😂 , but looking into all the suggestions above for more longterm solutions.
Copy code
pbpaste | kotlinc-jvm | tail -n +3 | sed '$d' | sed 's/^.*kotlin.String = //g' | pbcopy
1. For this command, so the idea is to take the output it copies to the clipboard and register that as your operation? Sorry had a little trouble following 2. I tried turning on generateOperationOutput but haven't been able to locate the json file or where it is outputting to. 😣 Apologies for being a little dense
b
for 2. it should be in
build/generated/operationOutput/apollo/service/operationOutput.json
🙏 1
w
For this command, so the idea is to take the output it copies to the clipboard and register that as your operation?
I don’t register the operations, I was just sharing my way of getting the exact query (functionally) that Apollo will make
🙌 1
s
Cool, thanks all, makes sense
Sorry one more think Łukasz, where do i put the string in relation to the command, do I replace a part of the command or put it after?
Copy code
pbpaste | kotlinc-jvm | tail -n +3 | sed '$d' | sed 's/^.*kotlin.String = //g' | pbcopy "query SomeQuery ..."
like this?
w
the
pbpaste
will paste the string from the clipboard, and
pbcopy
will copy it back. So this works when you copy the query string from the
SomeQuery
file to the clipboard, run the command I pasted (without changes, and provided you have kotlinc-jvm in your path), and it’ll put the cleaned up query in your clipboard
If any of those are not convenient, then I suggest just pasting the query string into the Kotlin scratch file in the IDE
s
Ahh ok gotcha now, don't know why I was missing that before