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

Deprication Warning while calling fromCursorHash #110

Open
abhi-dasgupta opened this issue Feb 13, 2020 · 5 comments
Open

Deprication Warning while calling fromCursorHash #110

abhi-dasgupta opened this issue Feb 13, 2020 · 5 comments

Comments

@abhi-dasgupta
Copy link

First of all, thank you so much for your awesome books and other resources!
I am on Road To GraphQL now! Pagination part

I am getting below mentioned depreciation warning, while fromCursorHash is called. Everything works fine, but I want to know what is causing this warning, can't figure. Anyone else?

Also, I am eagerly waiting for the 2020 update of this book. Thank you again :)

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Date(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be removed in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments: 
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: Fri Feb 14 2020 00:52:17 GMT+0530 (India Standard Time), _f: undefined, _strict: undefined, _locale: [object Object]
Error: 
    at Function.createFromInputFallback (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:320:98)
    at configFromString (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:2385:15)
    at configFromInput (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:2611:13)
    at prepareConfig (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:2594:13)
    at createFromConfig (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:2561:44)
    at createLocalOrUTC (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:2648:16)
    at createLocal (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:2652:16)
    at hooks (/home/abhi-dasgupta/dev/server/node_modules/moment/moment.js:12:29)
    at DATE._applyTimezone (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/data-types.js:460:21)
    at DATE._stringify (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/data-types.js:465:17)
    at DATE._stringify (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/postgres/data-types.js:175:20)
    at DATE.stringify (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/data-types.js:23:19)
    at PostgresQueryGenerator.escape (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:976:30)
    at PostgresQueryGenerator._whereParseSingleValueObject (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2556:41)
    at PostgresQueryGenerator.whereItemQuery (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2272:21)
    at /home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2173:25
    at Array.forEach (<anonymous>)
    at PostgresQueryGenerator.whereItemsQuery (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2171:35)
    at PostgresQueryGenerator.getWhereConditions (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:2583:19)
    at PostgresQueryGenerator.selectQuery (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/dialects/abstract/query-generator.js:1315:28)
    at QueryInterface.select (/home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/query-interface.js:1122:27)
    at /home/abhi-dasgupta/dev/server/node_modules/sequelize/lib/model.js:1757:34
Executing (default): SELECT "id", "title", "text", "createdAt", "updatedAt", "userId" FROM "messages" AS "message" WHERE "message"."createdAt" < '2020-02-13 19:22:17.000 +00:00' ORDER BY "message"."createdAt" DESC LIMIT 2;
@rwieruch
Copy link
Member

Thanks for reporting! Will definitely check this for the new book edition 👍

@abhi-dasgupta
Copy link
Author

abhi-dasgupta commented Feb 15, 2020

so I removed the graphql-iso-date package and used String scalar, with momentjs to format it

import moment from "moment";
import Sequelize from "sequelize";

const toCursorString = string => Buffer.from(string).toString("base64");
const fromCursorString = string =>
  Buffer.from(string, "base64").toString("ascii");

export default {
  Query: {
    messages: async (parent, { limit = 100, cursor }, { models }) => {
      const cursorOptions = cursor
        ? {
            where: {
              createdAt: {
                [Sequelize.Op.lt]: fromCursorString(cursor)
              }
            }
          }
        : null;
      const messages = await models.Message.findAll({
        order: [["createdAt", "DESC"]],
        limit: limit + 1,
        ...cursorOptions
      });
      const hasNextPage = messages.length > limit;
      const edges = hasNextPage ? messages.slice(0, -1) : messages;
      return {
        edges,
        pageInfo: {
          hasNextPage,
          endCursor: toCursorString(
            moment(edges[edges.length - 1].createdAt)
              .local()
              .format()
          )
        }
      };
    }
  },
  Message: {
    createdAt: message => {
      return moment
        .utc(message.createdAt)
        .local()
        .format();
    }
  }
};

@rwieruch
Copy link
Member

Oh thanks! Maybe I will consider this for the book if it doesn't work out with the Scalar. I found the custom Scalar interesting for readers for the sake of learning about it :)

@abhi-dasgupta
Copy link
Author

abhi-dasgupta commented Feb 15, 2020

ok, thank you for your consideration. I have another small suggestion for this topic, In the function to seed the database for development, instead of setting +1 sec to the date, it will make more sense if we did -1 sec. If we do +1 sec then the createdAt is always greater than updatedAt.
Not an issue at all as it will not hold true in production, but I was writing a client-side app simultaneously and faced some issues with logic while doing +1 sec

@rwieruch
Copy link
Member

Oh yeah, makes totally sense! Thanks for all the feedback :)

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

No branches or pull requests

2 participants