aarkerio
aarkerio

Reputation: 2354

Testing Apollo graphql query on AWS lambda web console

I can deploy and run successfully my lambda with a GraphqlClient in the URL:

https://4er563if.execute-api.us-east-1.amazonaws.com/dev/zipcodes

As far as I understand, that passes through the AWS API gateway that triggers the lambda, the gateway takes the POST data and delivers it to the lambda.

But now I want to try the code directly on the Lambda browser console. There is the option "Configure test event", where I can define and send a JSON string to the lambda, but I don't know what info "event" and "context" should hold.

I tried:

 {
   "headers": {"origin":true},
    "context": "{ \"functionName\": \"getZipdata\",
                  \"method\": \"POST\",
                  \"query\": getZipdata(zip: \"04340\") {id, name}}"
  }

but I'm getting:

  "body": "Apollo Server supports only GET/POST requests."

Upvotes: 2

Views: 938

Answers (1)

aarkerio
aarkerio

Reputation: 2354

I found the way!

{
    "headers": {
      "Accept": "application/json"
    },
    "path": "/zipcodes",
    "resource": "/zipcodes",
    "httpMethod": "POST",
    "body": "{\"query\":\"query {\\n  getZipdata(cp: \\\"78446\\\") {idmunicipio,municipio, asentamiento}\\n    }\",\"variables\":{},\"operationName\":null}"
  }

Upvotes: 3

Related Questions