简体   繁体   中英

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. When I go to my route that has the playground ( /playground ) it launches the playground interface however it just says:

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). 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

'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?

I had a similar problem using the Apollo server in combination with Kentico Cloud Headless CMS and I found this issue:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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