nicolaslopezj / meteor-apollo-accounts

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

Setup instructions with apollo-boost? #94

Open sgup opened 5 years ago

sgup commented 5 years ago

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 commented 5 years ago

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()
  }
})