question

atlars avatar image
atlars asked

GraphQL query in NodeJS fails with "There was a problem with the requested skill's response"

The below GraphQL request is based on this tutorial and the Alexa NodeJS HelloWorld boilerplate. After running the invocation name Alexa returns "There was a problem with the requested skill's response" . How to fix this issue?


const Alexa = require('ask-sdk-core');

const { GraphQLClient } = require('graphql-request');
const GRAPHQL_ENDPOINT = 'https://api.graph.cool/simple/v1/cixos23120m0n0173veiiwrjr';
const graphQLClient = new GraphQLClient(GRAPHQL_ENDPOINT, { })
const helloWorldQuery = `
    {
      Movie(title: "Inception") {
        releaseDate
        actors {
          name
        }
      }
    }
  `
  
const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  },
  handle(handlerInput) {
    const speechText = 'Welcome to the Alexa Skills Kit, you can say hello!';

    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .withSimpleCard('Hello World', speechText)
      .getResponse();
  },
};

const HelloWorldIntentHandler = {
 canHandle(handlerInput) {
 return (
      handlerInput.requestEnvelope.request.type === 'IntentRequest' && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent'
    );
  },
 async handle(handlerInput) {
 const response = await graphQLClient.request(helloWorldQuery);

 const speechText = `Hello World ${response}`;

 return handlerInput.responseBuilder
 .speak(speechText)
 // .withSimpleCard('GraphQL Query', speechText)
      .getResponse();
  },
};
alexa skills kitapinode_jsnodejsrequest
8 comments
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Have you tried logging out the response? Is there anything in the logs? If you are using AWS check cloudwatch for the logs of your lambda and try to find the error message. Other than that it looks correct.

2 Likes 2 ·

This is the CloudWatch Log - I'm using a custom skill with Alexa hosted. Any idea how to fix the error?

START RequestId: 1992effc-ec02-42fc-bd5f-22df89b16598 Version: 13
Unable to import module 'index': Error
at Function.Module._resolveFilename (module.js:547:15)
at Function.Module._load (module.js:474:25)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/var/task/index.js:6:27)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
END RequestId: 1992effc-ec02-42fc-bd5f-22df89b16598
0 Likes 0 ·

Yes. So to fix your code, open your package.json and add graphql-request package. Your package.json has to to look like this:

{
  "name": "hello-world",
  "version": "0.9.0",
  "description": "alexa utility for quickly building skills",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Amazon Alexa",
  "license": "ISC",
  "dependencies": {
    "ask-sdk-core": "^2.0.7",
    "ask-sdk-model": "^1.4.1",
    "aws-sdk": "^2.326.0",
    "graphql-request": "^1.8.2"
  }
}

The important line is graphl-request one. Overall, if you need other packages, they won't just magically appear, you need to add them to package json to get pulled.

Also I suggest to update speech output, where you say {response}. Change it to this to make more sense:

 const speechText = `Hello World ${response.Movie.actors.map(a => a.name).join(' ')}`;

I tested your code and it worked for me.

2 Likes 2 ·
Show more comments

0 Answers