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

Setup instructions with apollo-boost? #94

Open
sgup opened this issue Jun 21, 2019 · 1 comment
Open

Setup instructions with apollo-boost? #94

sgup opened this issue Jun 21, 2019 · 1 comment

Comments

@sgup
Copy link

sgup commented Jun 21, 2019

Hi, I'm quite new to apollo and trying to get meteor accounts access setup through graphQL.

How do I go about using the latest apollo instructions in conjunction with this package?

import { ApolloServer, gql } from 'apollo-server-express'
import { WebApp } from 'meteor/webapp'
import { getUser } from 'meteor/apollo'

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

const server = new ApolloServer({
  typeDefs,
  resolvers,
  context: async ({ req }) => ({
    user: await getUser(req.headers.authorization)
  })
})

server.applyMiddleware({
  app: WebApp.connectHandlers,
  path: '/graphql'
})

WebApp.connectHandlers.use('/graphql', (req, res) => {
  if (req.method === 'GET') {
    res.end()
  }
})
@sgup
Copy link
Author

sgup commented Jun 21, 2019

Ok I think i have the basics working.. hopefully this helps someone:

loadSchema with my typeDefs and resolvers wasn't working (it didn't merge my schema/resolvers with the Auth ones.

import { ApolloServer } from 'apollo-server-express'
import { WebApp } from 'meteor/webapp'
import { getUser } from 'meteor/apollo'
import {initAccounts} from 'meteor/nicolaslopezj:apollo-accounts'
import {getSchema} from 'graphql-loader'

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

// Load all accounts related resolvers and type definitions into graphql-loader
initAccounts({
  loginWithFacebook: false,
  loginWithGoogle: true,
  loginWithLinkedIn: false,
  loginWithPassword: true
})

const AuthSchema = getSchema()

const server = new ApolloServer({
  typeDefs: [...typeDefs, AuthSchema.typeDefs],
  resolvers: [resolvers, AuthSchema.resolvers],
  context: async ({ req }) => ({
    user: await getUser(req.headers.authorization)
  })
})

server.applyMiddleware({
  app: WebApp.connectHandlers,
  path: '/graphql'
})

WebApp.connectHandlers.use('/graphql', (req, res) => {
  if (req.method === 'GET') {
    res.end()
  }
})

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

1 participant