AppSync Pipeline Resolver Queries returning null

0

I'm attempting to make a simple pipeline resolver query, to eventually make a multi-function resolver. No matter what I change, this returns null. My desired query involves using an index to return an array of results, but I made a new query just to remove any added variables. I've looked up every piece of documentation I can find, but there's very little resources on these JS Pipeline resolvers and only 1 query example in the official docs.

Schema Query: getUserPermissions(id: String!): UserPermissions

My resolver setup: Enter image description here

AppSync Console Query Enter image description here

  • Do you have CLI access to your DynamoDB table?

  • I don't use CLI much, but I have access to it, yes.

  • Try do a GetItem from the CLI with the same parameters and see what result you get.

1 Answer
-1
Accepted Answer

I got a basic query with a single return to work using the example GetItem pipeline function.

I went back to my original query and kept messing with it. I eventually got it to work using this:

import { util } from '@aws-appsync/utils';
export function request(ctx) {
  return {
    operation: 'Query',
    index: 'userID-index',
    query: {
      expression: '#userID = :userID',
      expressionValues: util.dynamodb.toMapValues({ ':userID': ctx.args.userID }),
      expressionNames: { '#userID': 'userID' },
    },
  };
}

export function response(ctx) {
    return ctx.result;
}

Important notes: Ensure you've got expressionNames and your query in the Schema is setup to return ________Connection. It is not necessary to return ctx.result.items in the function or the after mapping template.

KapKerm
answered 9 months ago
profile picture
EXPERT
reviewed 6 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions