Express GraphQL必须提供查询字符串。

时间:2018-07-23 10:46:40

标签: javascript amazon-web-services express aws-lambda graphql

我是AWS lambda和GraphQL的新手。我正在尝试将Express GraphQL应用程序部署到AWS Lambda。

index.js文件

object demo 
{
  def main(args:Array[String]):Unit=
  {
      val temp: LinkedHashMap[String,Object]=new 
      LinkedHashMap[String,Object]()
      temp.put("apple", new Double(1));
      // here i received error since double is abstract class and cannot instantitaed
   }
}

enter image description here

但是在AWS Lambda控制台中执行AWS Lambda函数时出错。

  const awsServerlessExpress = require("aws-serverless-express");
  var express = require("express");
  var graphqlHTTP = require("express-graphql");
  var { buildSchema } = require("graphql");

  // Construct a schema, using GraphQL schema language
  var schema = buildSchema(`
    type Query {
         hello: String
        }
      `);

 // The root provides a resolver function for each API endpoint
 var root = {
  hello: () => {
    return "Hello world!";
  }
 };

 var app = express();
 app.use(
         "/",
         graphqlHTTP({
             schema: schema,
             rootValue: root,
             graphiql: true
           })
      );

   const server = awsServerlessExpress.createServer(app);

   exports.handler = (event, context) => 
        awsServerlessExpress.proxy(server, event, context);



 Expected Output:

enter image description here

1 个答案:

答案 0 :(得分:0)

您的服务器很好。我认为问题是您的查询。它以某种方式变形。由于您未包括在内,因此我们无法确定。但是,如果您的请求带有

,则可能会得到更好的结果
Content-Type: 'application/graphql'

Content-Type: 'application/json'

,然后使请求正文看起来像这样:

{"query": "{hello}" }

请注意引号的位置;如果是JSON,则必须采用类似JSON的格式。