Skip to content

Instantly share code, notes, and snippets.

@xavxyz
Created November 13, 2017 15:00
Show Gist options
  • Save xavxyz/1ef99718e529b9de6776d49ac282818c to your computer and use it in GitHub Desktop.
Save xavxyz/1ef99718e529b9de6776d49ac282818c to your computer and use it in GitHub Desktop.
Proposal for new API
// client
import { ApolloClient } from 'apollo-client';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { MeteorAccountsLink } from 'apollo-link-meteor-accounts';
const httpLink = new HttpLink({ uri: Meteor.absoluteUrl('graphql') });
const authLink = new MeteorAccountsLink();
const client = new ApolloClient({
link: authLink.concat(httpLink),
cache: new InMemoryCache(),
});
// server
import express from 'express';
import bodyParser from 'body-parser';
import { graphqlExpress, graphiqlExpress } from 'apollo-server-express';
import { getMeteorAccountsContext } from 'apollo-server-meteor-accounts';
const server = express();
server.use(
'/graphql',
bodyParser.json(),
graphqlExpress(async req => {
const userContext = await getMeteorAccountsContext(req);
return {
schema,
context: userContext,
};
})
);
server.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
WebApp.connectHandlers.use(server);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment