Sunday, 6 January 2019

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,



from Graphql Yoga Playground with Lambda - "Server cannot be reached"

No comments:

Post a Comment