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

Base64 encoding of date fails #46

Open
andersnylund opened this issue Jan 8, 2019 · 3 comments
Open

Base64 encoding of date fails #46

andersnylund opened this issue Jan 8, 2019 · 3 comments
Labels
bug Something isn't working Windows

Comments

@andersnylund
Copy link

The following functions caused me problems:

const toCursorHash = string => Buffer.from(string).toString('base64');
const fromCursorHash = string => (Buffer.from(string, 'base64').toString('utf-8');

Apparently the createdAt object passed to toCursorHash() was not of type string. I got the following error message:

TypeError [ERR_INVALID_ARG_TYPE]: The "value" argument must not be of type number. Received type number

Tested what type of the string is with javascripts typeof, and it revealed it to be of type object.

I fixed it with

const toCursorHash = string => Buffer.from(JSON.stringify(string)).toString('base64');
const fromCursorHash = string => JSON.parse(Buffer.from(string, 'base64').toString('utf-8'));

However, I'm curious of why this happened and why it appears to work for others as in the book.

Setup:

  • Windows 10 with WSL Ubuntu 18.04.1 LTS
  • Node v10.14.1
@rwieruch
Copy link
Member

Uh that's odd. I know that I fixed something for this subject before I released the book and hoped that everything should be alright now. Wondering whether anyone else ran into this issue.

CC @tmstani23 @pmosconi

@rwieruch rwieruch added bug Something isn't working Windows labels Jan 16, 2019
@pmosconi
Copy link

It looks strange to me too. I'm using node 8.11.3 and it works correctly without having to stringify the string.
Maybe check if what you are hashing is really a string, i.e.:
endCursor: toCursorHash(edges[edges.length - 1].createdAt.toString())

@tmstani23
Copy link

@andersnylund I used the following code and it works fine, I'm in windows 7 with node version 11.4.0

const toCursorHash = string => Buffer.from(string).toString('base64');
const fromCursorHash = string => Buffer.from(string, 'base64').toString('ascii');

cc:: @rwieruch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Windows
Projects
None yet
Development

No branches or pull requests

4 participants