Skip to content
This repository has been archived by the owner on Jan 27, 2022. It is now read-only.

The query hash that is generated by apollo-android does not match the query hash that is generated by apollo-link-persisted-queries #34

Open
tareq-khandaker-ck opened this issue Apr 30, 2019 · 0 comments

Comments

@tareq-khandaker-ck
Copy link

tareq-khandaker-ck commented Apr 30, 2019

Problem Description

The query hash that is generated by apollo-android does not match the query hash that is generated by apollo-link-persisted-queries.

Investigation

  1. I took a query and the query hash generated by apollo-android and found that query hash was different from the query hash that apollo-link-persisted-queries generates for the same query.

  2. I wrote a command-line utility that performed the same steps as apollo-link-persisted-queries:

    a. Read a query string.

    b. Perform a graphql parse on the output of a.

    c. Perform a graphql print on the output of b.

    d. Compute the SHA256 hash on the output of c.

  3. I found that my hash matched the one that apollo-link-persisted-queries generates.

  4. I looked at the code and saw that https://github.com/apollographql/apollo-android/blob/master/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/OperationTypeSpecBuilder.kt#L58 filters out newlines while https://github.com/apollographql/apollo-link-persisted-queries/blob/master/src/index.ts#L28-L31 does not.

  5. I added newline stripping to my utility in 2.

  6. I found that my hash now matched the one generated by apollo-android.

Proposed Solutions

There are two possible, mutually-exclusive solutions:

Either make the change inside apollo-android

Change https://github.com/apollographql/apollo-android/blob/master/apollo-compiler/src/main/kotlin/com/apollographql/apollo/compiler/OperationTypeSpecBuilder.kt#L58 to be:

        .initializer("\$S", operation.sourceWithFragments?.sha256())

Or make the change inside apollo-link-persisted-queries

Change https://github.com/apollographql/apollo-link-persisted-queries/blob/master/src/index.ts#L30 to be:

    .update(print(query).replace(/\n/g, ''))

Related PR

I raised the same issue in apollo-android here: apollographql/apollo-kotlin#1283 .

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant