Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
tareq-khandaker-ck opened this issue Apr 30, 2019 · 2 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 concern in apollo-link-persisted-queries here: apollographql/apollo-link-persisted-queries#34 .

@tasomaniac
Copy link
Contributor

@tareq-khandaker-ck can you check if you can reproduce this? Would be awesome to add a failing test case actually.

@sav007
Copy link
Contributor

sav007 commented Apr 13, 2020

Looks like apollo-link-persisted-queries is kinda not actively maintained, last commit was 2 years ago. Closing this issue as not really sure if we need to do anything here.

@sav007 sav007 closed this as completed Apr 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants