I'm trying to configure next setup: AppSync using lambda as a resolver for all queries and mutations. I have a problem with appsync resolver template ctx.info.variables. I can't understand what I have overlooked. Everything is looks pretty straightforward but variables in lambda is empty. In Lambda It looks like this in event
object:
...
variables: {},
...
Here is the simple schema:
input CreateSessionInput {
title: String!
}
type Session {
id: ID!
title: String!
}
type Mutation {
createSession(input: CreateSessionInput!): Session!
}
type Query {
getAllSessions: [Session!]!
}
I'm using default template of resolver. Here is resolver template:
import { util } from '@aws-appsync/utils';
/**
* Sends a request to a Lambda function. Passes all information about the request from the `info` object.
* @param {import('@aws-appsync/utils').Context} ctx the context
* @returns {import('@aws-appsync/utils').LambdaRequest} the request
*/
export function request(ctx) {
return {
operation: 'Invoke',
payload: {
fieldName: ctx.info.fieldName,
parentTypeName: ctx.info.parentTypeName,
variables: ctx.info.variables,
selectionSetList: ctx.info.selectionSetList,
selectionSetGraphQL: ctx.info.selectionSetGraphQL,
},
};
}
/**
* Process a Lambda function response
* @param {import('@aws-appsync/utils').Context} ctx the context
* @returns {*} the Lambda function response
*/
export function response(ctx) {
const { result, error } = ctx;
if (error) {
util.error(error.message, error.type, result);
}
return result;
}
Here is how I'm trying to access lambda variables.
...
export const handler = async (event) => {
console.log("Variables", event.variables);
...
Here is the log from lambda from event
object. Variables is just empty.
2024-03-31T18:56:13.558Z f481da1e-ba6d-4bc8-a06c-02460c6c731a INFO Start event {
fieldName: 'createSession',
parentTypeName: 'Mutation',
variables: {},
selectionSetList: [ 'id' ],
selectionSetGraphQL: '{\n id\n}'
}
In this log variables is just empty object.
May thanks in advance for any ideas or how to deal with this issue.