2

I'm new to AWS Appsync and to GraphQL.

Previously, I used to create REST APIs in Python. I was always creating a GET /health-check endpoint, sending back, for example and among many other info, the API version number, easily parsed from the project descriptor pyproject.toml file. That helped me massively to maintain APIs: with a single GET query in my browser, I was always able to instantly get if branch/version it was, the status of other services, etc. .

I want to do something similar with AWS Appsync / GraphQL and my IaC tool (Pulumi). Since I'm using IaC tool Pulumi in Python, I could still easily get the info I need and inject them in any resolver response template.

But if I create a resolver, should I create a corresponding health-check query itself in the GraphQL schema? When creating a resolver with a hardcoded JSON response, should it be associated with a GraphQL query in the schema, and if yes, how should that query in the schema look like?

bolino
  • 867
  • 1
  • 10
  • 27

1 Answers1

0

I finally found a way, but it's a very ugly workaround since AppSync VTL resolvers have a lot of limitations and since I'm using Pulumi as a Iac tool which also doesn't accept all arguments when creating a resolver - for example for GetItem operation it needs an id key in the request template.

I'm posting the workaround here anyway if it can be of any help to someone.

GraphQL schema:

schema {
  query: Query
}
type Query {
  getHealthCheck: String
}

AppSync getHealthCheck resolver request template:

{
    "version": "2018-05-29",
    "operation": "GetItem",
    "key": {
        "id": $util.dynamodb.toDynamoDBJson(""),
    },
}

AppSync getHealthCheck resolver response template example:

"'version':'0.1', 'branch':'staging', 'commitId':'abc123'"

So in a IaC tool like Pulumi using Python, one could build the response template like that:

"""
"'version':'{}', 'branch':'{}', 'commitId':'{}'"
""".format(
    version,
    os.environ.get("GITHUB_REF_NAME", "unknown"),
    os.environ.get("GITHUB_SHA", "unknown"),
),
bolino
  • 867
  • 1
  • 10
  • 27