Мой внешний интерфейс - localhost:3000
, а мой сервер GraphQL - localhost:3333
.
Я использовал response-apollo для запроса / изменения в земле JSX, но не сделал запрос / мутацию изЭкспресс еще.
Я хотел бы сделать запрос / мутацию здесь в моем server.js
.
server.get('/auth/github/callback', (req, res) => {
// send GraphQL mutation to add new user
});
Ниже, кажется, правильное направление, но я получаю TypeError: ApolloClient is not a constructor
:
const express = require('express');
const next = require('next');
const ApolloClient = require('apollo-boost');
const gql = require('graphql-tag');
// setup
const client = new ApolloClient({
uri: 'http://localhost:3333/graphql'
});
const app = next({dev});
const handle = app.getRequestHandler();
app
.prepare()
.then(() => {
const server = express();
server.get('/auth/github/callback', (req, res) => {
// GraphQL mutation
client.query({
query: gql`
mutation ADD_GITHUB_USER {
signInUpGithub(
email: "email@address.com"
githubAccount: "githubusername"
githubToken: "89qwrui234nf0"
) {
id
email
githubToken
githubAccount
}
}
`,
})
.then(data => console.log(data))
.catch(error => console.error(error));
});
server.listen(3333, err => {
if (err) throw err;
console.log(`Ready on http://localhost:3333`);
});
})
.catch(ex => {
console.error(ex.stack);
process.exit(1);
});
В этом посте Аполлон упоминается как решение , но не приводится пример.
Как вызвать мутацию GraphQL с сервера Express :3000
в GraphQL :3333
?