Created
November 13, 2017 15:00
-
-
Save xavxyz/1ef99718e529b9de6776d49ac282818c to your computer and use it in GitHub Desktop.
Proposal for new API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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