nicolaslopezj / meteor-apollo-accounts

Meteor accounts in GraphQL
MIT License
146 stars 37 forks source link

Float cannot represent non numeric value: {} #90

Open smeijer opened 5 years ago

smeijer commented 5 years ago

I've upgraded the apollo and graphql packages to it's latests versions; and thereby broke this package login method.

message: "Float cannot represent non numeric value: {}"
path: ["loginWithPassword", "tokenExpires"]
0: "loginWithPassword"
1: "tokenExpires"

Changed dependencies since it was working:

apollo-server-express:  1.3.6  >  2.1.0
graphql:                0.12.x > 14.0.2
graphql-tag:            1.0.x  >  2.9.2
graphql-tools:          3.0.4  >  4.0.0

meteor-apollo-accounts: 2.0.3   // unchanged

Meteor:

Meteor 1.7.0.3

accounts-password              1.5.1
apollo                         3.0.0
nicolaslopezj:apollo-accounts  3.2.2
ujwal-setlur commented 5 years ago

Have the same issue

ujwal-setlur commented 5 years ago

The following patch fixes it:

diff --git a/src/Auth.js b/src/Auth.js
index ff3825e..0ee8c54 100644
--- a/src/Auth.js
+++ b/src/Auth.js
@@ -7,7 +7,7 @@ type LoginMethodResponse {
   # Token of the connection
   token: String!
   # Expiration date for the token
-  tokenExpires: Float!
+  tokenExpires: String!
   # The logged in user
   user: User
 }

Seems to indicate that whatever Meteor is sending for tokenExpires to graphQL is a Date, and earlier it could parse it into a float, but not anymore. Guess graphql tightened it's parser.

smeijer commented 5 years ago

A patch would be nice highly needed, but I guess it means that you lose earlier GraphQL versions?

ujwal-setlur commented 5 years ago

I am not sure, I think earlier graphql packages will also parse it as a String when the type is changed here. Remember, meteor has not changed here.

joncursi commented 5 years ago

How do you apply this patch in a production environment? Has anyone created a fork that we can use?

ujwal-setlur commented 5 years ago

I have a fork. it's meant to work with cultofcoders:apollo, but might work other apollo environments.

meteor add ujwal:apollo-accounts
callmephilip commented 5 years ago

Managed to patch this as follows:

import { ApolloServer } from 'apollo-server-express';
import { loadSchema, getSchema } from 'graphql-loader';
import { makeExecutableSchema } from 'graphql-tools';
import { initAccounts } from 'meteor/nicolaslopezj:apollo-accounts';

initAccounts({
  loginWithFacebook: false,
  loginWithGoogle: false,
  loginWithLinkedIn: false,
  loginWithPassword: true,
});

// RE: https://github.com/orionsoft/meteor-apollo-accounts/issues/90
const schema = getSchema();
schema.typeDefs = schema.typeDefs.replace('tokenExpires: Float!', 'tokenExpires: String!');

/* ... */

EDIT:

looks like tokenExpires returns "Invalid Date". probably need to look into the resolver on the server side

EDIT:

Here's an extended patch to make sure expiration date is transmitted and parsed properly. @nicolaslopezj i'll be willing to PR if you take this

// RE: https://github.com/orionsoft/meteor-apollo-accounts/issues/90
const schema = getSchema();
schema.typeDefs = schema.typeDefs.replace('tokenExpires: Float!', 'tokenExpires: String!');
_.extend(schema.resolvers.LoginMethodResponse, schema.resolvers.LoginMethodResponse, {
  tokenExpires({ tokenExpires }) {
    return tokenExpires.toString();
  },
});