Nextjs при использовании обещаний внутри app.prepare (). Then () Ошибка: getaddrinfo ENOTFOUND undefined - PullRequest
1 голос
/ 20 сентября 2019

Я настраиваю новый сервер, используя nextJS, и я хотел бы иметь конечную точку graphql в моем приложении.Эта настройка прекрасно работает при использовании 2 серверов, однако у нас есть доступ только к 1 серверу, поэтому теперь я перемещаю сервер GraphQL на мой сервер экспресс.

Server.js

import express from 'express'
import next from 'next'
import pg from 'pg'
import expressGraphiqlMiddleware from 'express-graphiql-middleware'
import requestProxy from 'express-request-proxy'

import ConnectionFilterPlugin from 'postgraphile-plugin-connection-filter'
const { ApolloServer } = require('apollo-server-express')
const { makeSchemaAndPlugin } = require('postgraphile-apollo-server')

....

app
  .prepare()
  .then(async () => {
    const { schema, plugin } = await makeSchemaAndPlugin(
      pgPool,
      'public', // PostgreSQL schema to use
      {
        appendPlugins: [ConnectionFilterPlugin],
        graphiql: true,
        // PostGraphile options, see:
        // https://www.graphile.org/postgraphile/usage-library/
      }
    )
    ...
    const expressServer = express()
    ...    
    expressServer.get('/p/:id', (req, res) => {
      const actualPage = '/post'
      const queryParams = { title: req.params.id }
      app.render(req, res, actualPage, queryParams)
    })
    ...    
    //Scraping Tools
    scrape(expressServer)

    expressServer.get('*', (req, res) => {
      return handle(req, res)
    })
    ...    
    expressServer.listen(3001, err => {
      if (err) throw err
      console.log('> Ready on http://localhost:3001')
    })
  })
  .catch(ex => {
    console.info('error')
    console.error(ex.stack)
    process.exit(1)
  })

У меня естьУпростил мой пример, но ключевой момент здесь: если я удалю async / await / обещание из текущего then(), я получу следующую ошибку:

Error: Apollo Server requires either an existing schema, modules or typeDefs

Что касается курса, schema иplugin не будет определен, однако, если я включу эти обещания, я получу: как ошибку

ror.js
 generate SourceMap

error
Error: getaddrinfo ENOTFOUND undefined
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Waiting for the debugger to disconnect...
...