aws-lambdaaws-appsyncaws-appsync-resolver

AppSyncJS selectionSetList is undefined in info object


I have the following AppSyncJS Resolver request function and I'm using a Lambda function as Data Source:

export function request(ctx) {
    return {
        operation: 'Invoke',
        payload: {
            arguments: ctx.arguments,
            source: ctx.source,
            request: ctx.request,
            info: ctx.info,
            prev: ctx.prev,
            stash: ctx.stash,
            infoselectionSetList: ctx.info.selectionSetList,
            selectionSetGraphQL: ctx.info.selectionSetGraphQL,
        },
    };
}

The Lambda function is written in TypeScript and the handler function is declared like this:

export async function handler (event: AppSyncResolverEvent<any, any>)

the property selectionSetList is declared on type AppSyncResolverEvent.info, but is undefined, if I call console.log(event.info) the result is this:

info: {
    fieldName: 'getPost',
    parentTypeName: 'Query',
    variables: {}
  }

I expected the selectionSetList and selectionSetGraphQL parameters to also appear inside the info object, but they are undefined, but they appear outside the info object, if I call console.log(event) I notice that the infoselectionSetList and selectionSetGraphQL fields that I valued in the resolver contain the data I need.

This thing is driving me mad, if in the resolver I have declared the info object to be ctx.info it must also contain selectionSetList and selectionSetGraphQL, and if those two values are not there then I expect them not to be there even when I value infoselectionSetList and selectionSetGraphQL inside the payload in the resolver.


Solution

  • Ok, if I write the request function in the AppSyncJS Resolver like this it works:

    export function request(ctx) {
        return {
            operation: 'Invoke',
            payload: {
                arguments: ctx.arguments,
                source: ctx.source,
                request: ctx.request,
                info: {
                    fieldName: ctx.info.fieldName,
                    parentTypeName: ctx.info.parentTypeName,
                    variables: ctx.info.variables,
                    selectionSetList: ctx.info.selectionSetList,
                    selectionSetGraphQL: ctx.info.selectionSetGraphQL
                },
                prev: ctx.prev,
                stash: ctx.stash
            },
        };
    }
    

    Now, I have absolutely no idea why this works, why is different from this:

    export function request(ctx) {
       return {
           operation: 'Invoke',
           payload: {
               arguments: ctx.arguments,
               source: ctx.source,
               request: ctx.request,
               info: ctx.info,
               prev: ctx.prev,
               stash: ctx.stash
           },
       };
    }