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

Trouble in initial set up. #57

Closed
vladinator1000 opened this issue Jul 26, 2016 · 9 comments
Closed

Trouble in initial set up. #57

vladinator1000 opened this issue Jul 26, 2016 · 9 comments

Comments

@vladinator1000
Copy link

Hey there, I'm a beginner and I'm having trouble setting up.

import express from 'express';
import { apolloServer } from 'apollo-server';

import Schema from './schema';
import Resolvers from './resolvers';

const GRAPHQL_PORT = 3000;

const app = express();

app.use('/graphql', apolloServer({
  graphiql: true, 
  pretty: true,
  schema: Schema,
  resolvers: Resolvers
}));

app.listen(GRAPHQL_PORT, () => console.log(
  `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphql`
));

I've installed everything but I get this weird error:

app.use('/graphql', (0, _apolloServer.apolloServer)({
                                                   ^

TypeError: (0 , _apolloServer.apolloServer) is not a function
    at Object.<anonymous> (server.js:11:21)
    at Module._compile (module.js:541:32)
    at loader (/Users/Empyreal/WebProjects/knex-2/node_modules/babel-register/lib/node.js:158:5)
    at Object.require.extensions.(anonymous function) [as .js] (/Users/Empyreal/WebProjects/knex-2/node_modules/babel-register/lib/node.js:168:7)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Function.Module.runMain (module.js:575:10)
    at /Users/Empyreal/WebProjects/knex-2/node_modules/babel-cli/lib/_babel-node.js:160:24
    at Object.<anonymous> (/Users/Empyreal/WebProjects/knex-2/node_modules/babel-cli/lib/_babel-node.js:161:7)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:458:32)
    at tryModuleLoad (module.js:417:12)
    at Function.Module._load (module.js:409:3)
    at Module.runMain (module.js:575:10)
@rszewczyk
Copy link

rszewczyk commented Jul 26, 2016

I ran into the same problem. It looks like there were breaking changes from v0.1.5 to the current version (0.2.0-rc.1) that aren't yet covered in the tech preview docs. If you install v0.1.5, you should have better luck.

Actually, I didn't feel satisfied with the above answer, so here's what I was able to get working with the current version:
https://gist.github.com/rszewczyk/9408f0aa70b33b20d5372f23474bee4e

@HriBB
Copy link
Contributor

HriBB commented Jul 26, 2016

This is my setup with 0.2.0-rc.1, hope it helps ...

import express from 'express'
import cors from 'cors'
import bodyParser from 'body-parser'
import async from 'asyncawait/async'
import await from 'asyncawait/await'
import { apolloExpress, graphiqlExpress } from 'apollo-server'
import { makeExecutableSchema } from 'graphql-tools'
import schema from './server/data/schema'
import resolvers from './server/data/resolvers'
import config from './config'

// create express server
const app = express()

// use cors
app.use(cors())

// use bodyparser
app.use(bodyParser.urlencoded({ extended: true }))
app.use(bodyParser.json())

...

// graphql endpoint
app.use('/graphql', apolloExpress(async (req) => {
  const user = await getAuthenticatedUser(req)
  return {
    schema: makeExecutableSchema({
      typeDefs: schema,
      resolvers,
      allowUndefinedInResolve: true,
    }),
    context: { user } // add user to the context
  }
}))

// graphiql endpoint
app.use('/graphiql', graphiqlExpress({
  endpointURL: '/graphql',
}))

// start express server
app.listen(config.server.port, () => console.log(
  `==> GraphQL Server is now running on http://localhost:${config.server.port}`
))

@nnance
Copy link
Contributor

nnance commented Jul 26, 2016

@savovs @HriBB Guys, @rszewczyk is correct. We made a mistake and released an RC version of the project to NPM. We have fixed the problem and now when you npm install apollo-server you will get version 0.1.5 which is the working version. Please make sure you use this version until we get the release candidate fully working and documented.

Sorry for any hassle this may have caused.

@helfer
Copy link
Contributor

helfer commented Jul 27, 2016

I believe this is fixed now. Feel free to re-open if it's still not working for you.

@helfer helfer closed this as completed Jul 27, 2016
@scottmcpherson
Copy link

@helfer @nnance I'm still getting this error with a fresh install of apollo in a Meteor integration:

W20160810-06:05:07.119(-4)? (STDERR) TypeError: apolloServer is not a function
W20160810-06:05:07.119(-4)? (STDERR)     at createApolloServer (packages/apollo/main-server.js:21:34)
W20160810-06:05:07.120(-4)? (STDERR)     at meteorInstall.server.server.js (server/server.js:5:1)
W20160810-06:05:07.121(-4)? (STDERR)     at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
W20160810-06:05:07.121(-4)? (STDERR)     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
W20160810-06:05:07.121(-4)? (STDERR)     at /Users/scott/Develop/Meteor/AdAbounds/.meteor/local/build/programs/server/app/app.js:89:1
W20160810-06:05:07.122(-4)? (STDERR)     at /Users/scott/Develop/Meteor/AdAbounds/.meteor/local/build/programs/server/boot.js:297:10
W20160810-06:05:07.122(-4)? (STDERR)     at Array.forEach (native)
W20160810-06:05:07.122(-4)? (STDERR)     at Function._.each._.forEach (/Users/scott/.meteor/packages/meteor-tool/.1.4.0-1.nv68bz++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20160810-06:05:07.123(-4)? (STDERR)     at /Users/scott/Develop/Meteor/AdAbounds/.meteor/local/build/programs/server/boot.js:133:5
W20160810-06:05:14.321(-4)? (STDERR) WARNING: npm peer requirements (for apollo) not installed:
W20160810-06:05:14.322(-4)? (STDERR)  - apollo-server@0.2.4 installed, apollo-server@^0.1.1 needed

It looks like the latest apollo-server@0.2.4 is incompatible with the apollo atmosphere package?

  • Meteor 1.4.0.1
  • apollo@0.0.3
  • apollo-server@0.2.4

@Grmiade
Copy link

Grmiade commented Aug 10, 2016

@scottmcpherson
Copy link

scottmcpherson commented Aug 10, 2016

Thanks @Grmiade :) I guess I'm not 100% sure how this ties in with the apollo atmosphere package and the createApolloServer function.

I'm guessing the apollo atmosphere package still uses the old apolloServer?

Right now, in my server.js I'm using the createApolloServer function:

import { createApolloServer } from 'meteor/apollo';
import { schema, resolvers } from '/imports/api/schema';

createApolloServer({
  graphiql: true,
  pretty: true,
  schema,
  resolvers,
});

Do you know if createApolloServer is no longer the recommended approach in a Meteor app?

@scottmcpherson
Copy link

I'm guessing the apollo atmosphere package still uses the old apolloServer?

Found the answer to the first question:
https://github.com/apollostack/meteor-integration/blob/master/main-server.js#L3

@bwhitty
Copy link

bwhitty commented Aug 10, 2016

The answer to your question is on the last two lines:

W20160810-06:05:14.321(-4)? (STDERR) WARNING: npm peer requirements (for apollo) not installed:
W20160810-06:05:14.322(-4)? (STDERR)  - apollo-server@0.2.4 installed, apollo-server@^0.1.1 needed

The meteor integration currently only supports apollo server 0.1.x, but you have the backwards incompatible 0.2.x installed. You need to make sure you have the correct version of Apollo server installed.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants