0

I am using a lambda as a resolver for a GraphQL Query from AppSync. When I run the Query from AppSync Console, the lambda works fine and returns the requested data, but on the AppSync console, the results show null values on the defined query arguments.

This is the schema:

type usersData {
    email: String
    photos: photos
}

type photos {
    profile_photo: String
    background_photo: String
}

type Query {
    getUsersData(email: String!): usersData
}

schema {
    query: Query
}

This is the query:

query getUsersData {
  getUsersData(email: "lambda10@test.com") {
    email
    photos {
      profile_photo
      background_photo
    }
  }
}

This is the result from the lambda resolver:

{
    "email": "lambda10@test.com",
    "photos": {
        "profile_photo": "./test1/test1",
        "background_photo": "./test1/test1"
    }
}

This is the result from the query on AppSync Console:

{
  "data": {
    "getUsersData": {
      "email": null,
      "photos": null
    }
  }
}

Any idea why is that?

ISimion
  • 108
  • 8
  • Did you resolve this as I am getting the exact same issue, I can see in the logs the response is making it to AppSync and if I call the lambda directly I get the response back, but calling from the AppSync console I get null – berimbolo Feb 23 '23 at 16:12
  • I remember this one, but only vaguely the solution. It was something to do with the lambda function, even though it returned seemingly the right output, it did not actually for the graph query to understand it. Looking now at the code the way I return from lambda the response is by using this line ```json.loads(json_util.dumps(record))```. Maybe this will help. – ISimion Feb 25 '23 at 09:57
  • 1
    Thanks, I was able to pin it down to the lambda functions response not matching the expected schema, it turned out that I didn't need to use `json.dumps()` at all and returning the dictionary 'as-is' resolved the issue. – berimbolo Feb 27 '23 at 11:19

0 Answers0