I am a newbie for Apollo
.
I base on Meteor + Vue
.
With one better DDP VS HTTP
?
(meteor/apollo, swydo:ddp-apollo, cultofcoders:apollo)
I am a newbie for Apollo
.
I base on Meteor + Vue
.
With one better DDP VS HTTP
?
(meteor/apollo, swydo:ddp-apollo, cultofcoders:apollo)
I just do something like this and use http
import { ApolloServer } from 'apollo-server-express';
import { WebApp } from 'meteor/webapp';
import { typeDefs, resolvers } from '/imports/api/schema';
import { getSchema } from 'graphql-loader';
import { merge } from 'lodash';
import { initAccounts } from 'meteor/nicolaslopezj:apollo-accounts';
import { applyMiddleware } from 'graphql-middleware';
import { makeExecutableSchema } from 'graphql-tools';
// internal files
import getUser from './getUser';
//set options
// Load all accounts related resolvers and type definitions into graphql-loader
initAccounts({
loginWithPassword: true
});
// we need to do this to initialize meteor-apollo-accounts
const authSchema = getSchema();
// now this is ugly, we are doing a few things here
// 1. applyMiddleware is needed for permissions with graphql-shield
// 2. makeExecutableSchema is used to combine our schema with the permissions before passing it into applyMiddleware
// 3. authSchema.typeDefs & authSchema.resolvers are the resolvers/typeDefs coming from meteor-apollo-accounts
// 4. we merge our custom stuff (typesdefs/resolvers) with the meteor-apollo-accounts ones
const schema = applyMiddleware(
makeExecutableSchema({
typeDefs: merge(authSchema.typeDefs, typeDefs),
resolvers: merge(authSchema.resolvers, resolvers)
})
);
const server = new ApolloServer({
schema,
context: async ({ req }) => ({
user: await getUser(req.headers['meteor-login-token'])
})
});
server.applyMiddleware({
app: WebApp.connectHandlers,
path: '/graphql'
});
WebApp.connectHandlers.use('/graphql', (req, res) => {
if (req.method === 'GET') {
res.end();
}
});
then I create a separate create-react-app
If you start from scratch the easiest route is probably a default GraphQL setup. No real need for DDP or Meteor specific setup, unless you want to use the Meteor accounts system.
DDP-Apollo was created for Meteor users who already had an app and wanted to add GraphQL. It helps to get started quickly with support for Meteor specific APIs. For example, having a userId in your SimpleSchema or when you call a Meteor method within a resolver.
With a new app, you probably haven’t invested heavily in Meteor code yet and can go the default node/GraphQL route. A nice thing of DDP-Apollo is that subscriptions work out of the box, but you can set that up yourself as well.
So in short: use a default Apollo setup unless you already invested heavily in a Meteor specific app.
@jamiter, very thanks for your reply.
I am a newbie for Apollo
, but would like to try with New Project
(Not Existing).
So should setup via Integrating with Meteor
(And use Meteor App: swydo:ddp-apollo
)
You choose either the default Meteor integration OR DDP-Apollo. No use in trying to combine them. For new projects I advice to go the default route. DDP-Apollo was designed for Meteor users who already invested a lot in their Meteor application and wanted to start using GraphQL. DDP-Apollo is the simplest route for that, but has it’s own limitations.
Very thanks again