nicolaslopezj / meteor-apollo-accounts

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

initAccounts is not a function #42

Closed rwaness closed 7 years ago

rwaness commented 7 years ago

Hello,

I'm trying to use meteor-apollo-accounts, with the tutorial http://dev.apollodata.com/core/meteor.html and your README.md.

So now I have :

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

import { typeDefs } from '/imports/api/schema';
import { resolvers } from '/imports/api/resolvers';

const options = {}
// Load all accounts related resolvers and type definitions into graphql-loader
initAccounts(options)

// Load all your resolvers and type definitions into graphql-loader
loadSchema({typeDefs, resolvers})

// Gets all the resolvers and type definitions loaded in graphql-loader
const schema = getSchema()
const executableSchema = makeExecutableSchema(schema)

createApolloServer({
     executableSchema,
});

when I launch the application, my server crash :

W20170202-17:22:45.325(-5)? (STDERR) Note: you are using a pure-JavaScript implementation of bcrypt.
W20170202-17:22:45.325(-5)? (STDERR) While this implementation will work correctly, it is known to be
W20170202-17:22:45.326(-5)? (STDERR) approximately three times slower than the native implementation.
W20170202-17:22:45.326(-5)? (STDERR) In order to use the native implementation instead, run
W20170202-17:22:45.326(-5)? (STDERR)
W20170202-17:22:45.327(-5)? (STDERR)   meteor npm install --save bcrypt
W20170202-17:22:45.327(-5)? (STDERR)
W20170202-17:22:45.327(-5)? (STDERR) in the root directory of your application.
W20170202-17:22:45.348(-5)? (STDERR) WARNING: npm peer requirements (for apollo) not installed:
W20170202-17:22:45.348(-5)? (STDERR)  - graphql-server-express@0.6.0 installed, graphql-server-express@^0.4.3 needed
W20170202-17:22:45.349(-5)? (STDERR)  - graphql@0.9.1 installed, graphql@^0.7.0 || ^0.8.0 needed
W20170202-17:22:45.349(-5)? (STDERR)  - graphql-tools@0.9.2 installed, graphql-tools@^0.8.0 needed
W20170202-17:22:45.349(-5)? (STDERR)
W20170202-17:22:45.350(-5)? (STDERR) Read more about installing npm peer dependencies:
W20170202-17:22:45.350(-5)? (STDERR)   http://guide.meteor.com/using-packages.html#peer-npm-dependencies
W20170202-17:22:45.350(-5)? (STDERR)
W20170202-17:22:45.639(-5)? (STDERR) C:\Users\Erwan\AppData\Local\.meteor\packages\meteor-tool\1.4.2_3\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280
W20170202-17:22:45.639(-5)? (STDERR)                                            throw(ex);
W20170202-17:22:45.639(-5)? (STDERR)                                            ^
W20170202-17:22:45.640(-5)? (STDERR)
W20170202-17:22:45.640(-5)? (STDERR) TypeError: initAccounts is not a function
W20170202-17:22:45.641(-5)? (STDERR)     at server/main.js:19:2
W20170202-17:22:45.641(-5)? (STDERR)     at Function.time (C:\Users\Erwan\Documents\Perso\Travaux\looc\api-server\.meteor\local\build\programs\server\profile.js:301:28)
W20170202-17:22:45.641(-5)? (STDERR)     at C:\Users\Erwan\Documents\Perso\Travaux\looc\api-server\.meteor\local\build\programs\server\boot.js:304:13
W20170202-17:22:45.642(-5)? (STDERR)     at C:\Users\Erwan\Documents\Perso\Travaux\looc\api-server\.meteor\local\build\programs\server\boot.js:345:5
W20170202-17:22:45.642(-5)? (STDERR)     at Function.run (C:\Users\Erwan\Documents\Perso\Travaux\looc\api-server\.meteor\local\build\programs\server\profile.js:480:12)
W20170202-17:22:45.642(-5)? (STDERR)     at C:\Users\Erwan\Documents\Perso\Travaux\looc\api-server\.meteor\local\build\programs\server\boot.js:343:11
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.

I really don't understand. Is the tutorial up-to-date ?

thanks in advance, and good job 👍 I really need it ^^

dbrrt commented 7 years ago

@rwaness Sorry for the delay, initAccounts might not be exported, or maybe not exist in the version of apollo-accounts you have installed. I can help you with that.

rwaness commented 7 years ago

@dbrrt thanks for you answer.

So what should I do ?

dbrrt commented 7 years ago

@rwaness

  1. Figure out why "TypeError: initAccounts is not a function"
  2. Checking if there's no conflicts between packages versions (graphlql/graphql-express/graphql-tools)

I'm running this repository's code on a WIP Apollo/GraphQL based app, so it's working. Even tried with React Native.

Can you share some code, your project (if not confidential) to reproduce the trace?

ahsanwtc commented 7 years ago

I am also getting the same issue. Did you manage to find the solution?

dbrrt commented 7 years ago

@ahsanwtc Here's my server.js file, actually I'm using initAccounts not directly from the Meteor library but it should work in both cases. Maybe the version on Atmosphere is not the later version, I'll try it.

import {makeExecutableSchema} from 'graphql-tools'
import {loadSchema, getSchema} from 'graphql-loader'
import {initAccounts} from '/imports/lib/accounts-gql/server'

import typeDefs from './schema'
import resolvers from './resolvers'

import {createApolloServer} from 'meteor/orionsoft:apollo'
import cors from 'cors'

const options = {}
// Load all accounts related resolvers and type definitions into graphql-loader
initAccounts(options)

// Load all your resolvers and type definitions into graphql-loader
loadSchema({typeDefs, resolvers})

// Gets all the resolvers and type definitions loaded in graphql-loader
const schema = getSchema()

const executableSchema = makeExecutableSchema(schema)

createApolloServer({
  schema: executableSchema
  }, {
  configServer (graphQLServer) {
    graphQLServer.use(cors())
  }
})
ahsanwtc commented 7 years ago

@dbrrt thanks for the reply. Can you give the the full path to the initAccounts? I am not able to find the lib folder. It's not able to find the path '/imports/lib/accounts-gql/server'

dbrrt commented 7 years ago

I "repacked" the libraries (client and server), under the lib path, so that's just my project. But I think that if you can't use initAccounts, that's because of an export or something like that.

rwaness commented 7 years ago

thank you for your feed back.

I already share my code... all is here (juste a test to integrate apollo in an other app)

In fact there is dependencies issue... I will investigate but i'm pretty sure it's not the problem. If you can (of course), I'm very curious about your test result concerning the meteor initAccount method.

Thank a lot ;)

dbrrt commented 7 years ago

@rwaness Here's an extract of my packages.json, if that can help:

  "dependencies": {
    "apollo-client": "^0.5.0",
    "babel-runtime": "^6.20.0",
    "bcrypt": "^0.8.7",
    "body-parser": "^1.16.0",
    "classnames": "^2.2.5",
    "cors": "^2.8.1",
    "express": "^4.14.0",
    "graphql": "^0.7.0",
    "graphql-loader": "^1.0.1",
    "graphql-server-express": "^0.4.3",
    "graphql-tools": "^0.8.0",
    "graphql-typings": "0.0.1-beta-2",
    "invariant": "^2.2.1",
    "meteor-node-stubs": "~0.2.0",
    "moment": "^2.17.1",
    "node-sass": "^3.13.1",
    "normalize.css": "^5.0.0",
    "react": "^15.3.1",
    "react-addons-css-transition-group": "~15.4.0",
    "react-addons-pure-render-mixin": "^15.3.1",
    "react-apollo": "^0.5.16",
    "react-dom": "^15.3.1",
    "react-komposer": "^1.13.1",
    "react-mounter": "^1.2.0",
    "react-redux": "^5.0.2",
    "react-router": "^3.0.2",
    "react-slick": "^0.14.6",
    "redux": "^3.6.0",
    "semantic-ui-css": "^2.2.4",
    "semantic-ui-react": "^0.64.3"
  },
  "devDependencies": {
    "babel-plugin-module-resolver": "^2.4.0",
    "babel-plugin-transform-class-properties": "^6.19.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "semantic-ui": "^2.2.7",
    "standard": "^8.5.0"
  }

and I didn't have time for now to reproduce your issue with initAccount (directly using the Meteor lib), I'll try ASAP

simsim0709 commented 7 years ago

@rwaness have you solved the problem? I think that's because the package version installed in your meteor app. You need to specify the version of this package. If not, 1.0.1 version is installed instead. Try this: meteor add nicolaslopezj:apollo-accounts@3.0.1

rwaness commented 7 years ago

All good with initAccount now. Thanks to you.

Unfortunatly, I found a second issue.

I follow this tutorial : https://blog.orionsoft.io/using-meteor-accounts-with-apollo-and-react-df3c89b46b17 and when I want to test the application, the server crash and say :

TypeError: Auth is not a function
     at meteorInstall.server.schema.Mutation.index.js (server/schema/Mutation/index.js:5:4)
     at fileEvaluate (packages\modules-runtime.js:197:9)
     at require (packages\modules-runtime.js:120:16)
     at C:\Users\erwan\Documents\Travaux\meteor\loocc\tests\api-server\.meteor\local\build\programs\server\app\app.js:220:1
     at C:\Users\erwan\Documents\Travaux\meteor\loocc\tests\api-server\.meteor\local\build\programs\server\boot.js:303:34
     at Array.forEach (native)
     at Function._.each._.forEach (C:\Users\erwan\AppData\Local\.meteor\packages\meteor-tool\1.4.3_2\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
     at C:\Users\erwan\Documents\Travaux\meteor\loocc\tests\api-server\.meteor\local\build\programs\server\boot.js:128:5
     at C:\Users\erwan\Documents\Travaux\meteor\loocc\tests\api-server\.meteor\local\build\programs\server\boot.js:352:5
     at Function.run (C:\Users\erwan\Documents\Travaux\meteor\loocc\tests\api-server\.meteor\local\build\programs\server\profile.js:510:12)

The file server/schema/Mutation/index.js looks like :

import {SchemaMutations as Auth} from 'meteor/nicolaslopezj:apollo-accounts'

export default `
type Mutation {
    ${Auth()}
}
`

Is it again a version issue ? How can we know the good version to use ?

Good job guys. Continue ;)

simsim0709 commented 7 years ago

@rwaness Yeah. I think that api version is old.

It has changed.

You better see this install guide.

Or, mine is like below:

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

import cors from 'cors';

import { typeDefs } from './schema';
import { resolvers } from './resolvers';

initAccounts({});
loadSchema({ typeDefs, resolvers });

const schema = makeExecutableSchema(getSchema());

export default () => {
  createApolloServer({ schema }, {
    configServer(graphQLServer) {
      graphQLServer.use(cors());
    },
  });
};
rwaness commented 7 years ago

Yes, it works with the boilerplate : https://github.com/orionsoft/server-boilerplate

Thanks ;)