简体   繁体   English

带有Lambda的Graphql瑜伽游乐场-“无法访问服务器”

[英]Graphql Yoga Playground with Lambda - “Server cannot be reached”

I'm in the process of setting a graphql endpoint with servlerless/ lambda and am receiving an error when trying to connect to the graphql playground that comes with graphql-yoga. 我正在使用servlerless / lambda设置graphql端点,并且在尝试连接到graphql-yoga附带的graphql游乐场时收到错误。 When I go to my route that has the playground ( /playground ) it launches the playground interface however it just says: 当我走到具有游乐场( /playground )的路线时,它会启动游乐场界面,但它只是说:

Server cannot be reached 无法访问服务器

In the top right of the playground. 在操场的右上方。 It's worth noting i'm using the makeRemoteExecutableSchema utility to proxy to another graphql endpoint (which is my CMS called Prismic). 值得注意的是,我正在使用makeRemoteExecutableSchema实用程序代理另一个graphql终结点(这是我的CMS,称为Prismic)。 I don't believe this is the issue as I have successfully connected to it with the playground when testing on a normal express server. 我不认为这是问题所在,因为在正常的快速服务器上进行测试时,我已经成功地将其连接到了游乐场。

Here is the code in my handler.js 这是我的handler.js中的代码

'use strict';

const { makeRemoteExecutableSchema } = require('graphql-tools');
const { PrismicLink } = require("apollo-link-prismic");
const { introspectSchema } = require('graphql-tools');
const { ACCESS_TOKEN, CMS_URL } = process.env;
const { GraphQLServerLambda } = require('graphql-yoga')

const lambda = async () => {
  const link = PrismicLink({
    uri: CMS_URL,
    accessToken: ACCESS_TOKEN
  });

  const schema = await introspectSchema(link);

  const executableSchema = makeRemoteExecutableSchema({
    schema,
    link,
  });

  return new GraphQLServerLambda({ 
    schema: executableSchema,
    context: req => ({ ...req })
  });
}

exports.playground = async (event, context, callback) => {
  context.callbackWaitsForEmptyEventLoop = false;
  const graphQl = await lambda();
  return graphQl.playgroundHandler(event, context, callback);
};

I have followed this guide for getting it running up till here and am fairly sure i've followed similar steps for what applies to what i'm trying to do but can't seem to figure out where i've gone wrong. 我一直按照指南进行操作,直到现在为止,并且可以肯定的是,对于要尝试执行的操作,我已经遵循了类似的步骤,但是似乎无法弄清楚哪里出了问题。

Thanks, 谢谢,

Could you take a look at what version of the graphql-yoga package you are using? 您能否看一下正在使用哪个版本的graphql-yoga软件包?

I had a similar problem using the Apollo server in combination with Kentico Cloud Headless CMS and I found this issue: 将Apollo服务器与Kentico Cloud Headless CMS结合使用时,我遇到了类似的问题,并且发现了以下问题:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM