Getting @aws_subscribe to work with CDK aws-appsync

0

For the application I'm building Amplify is an overkill. I've been able to manage to build graphQL with appsync and cdk only at this point. Now, I'm running into issue with @aws_subscribe -- it just does not work for me. I'm wondering if the directives like this require Amplify to be aded and initialized? Is there any way to initialize and process graphQL subscriptions with CDK api directly?

My schema.graphql contains certain definitions:

type Message{  
  chatUuid: String!
  uuid: String!
  messageUuid: String!
  text: String! 
  createdAt: AWSDateTime!  
  updatedAt: AWSDateTime!  
}

  sendMessage(
    chatUuid: String!
    uuid: String!
    messageUuid: String!
    text: String! 
  ): Message
   
}

type Subscription {
  onSendMessage(chatUuid: String!): Message    
    @aws_subscribe(mutations: ["sendMessage"])
}

And here is how I'm initializing my graphQL with CDK off of that definition file:

const api = new appsync.GraphqlApi(this, `${deployEnv()}-WiSaw-appsyncApi-cdk`,
      {
        name: `${deployEnv()}-cdk-wisaw-appsync-api`,
        schema: appsync.Schema.fromAsset('graphql/schema.graphql'),
        authorizationConfig: {
          defaultAuthorization: {
            authorizationType: appsync.AuthorizationType.API_KEY,
            apiKeyConfig: {
              expires: cdk.Expiration.after(cdk.Duration.days(365)),
            },
          },
        },
      })

For debugging purposes, tried to attach a resolver to the subscription:

export default async function main(
  event:any
) {

  console.log({event,})

  return {}
}

In the log see the following:

{
  event: {
    arguments: {},
    identity: null,
    source: null,
    request: { headers: [Object], domainName: null },
    prev: null,
    info: {
      selectionSetList: [Array],
      selectionSetGraphQL: '{\n  chatUuid\n  createdAt\n  messageUuid\n  text\n  updatedAt\n  uuid\n}',
      fieldName: 'onSendMessage',
      parentTypeName: 'Subscription',
      variables: {}
    },
    stash: {}
  }
}

At this point, I'm running out of things to try. Any help or direction would be highly appreciated.

  • I know this is definately possible. Am trying to recreate your example but it contains some typos.

preguntada hace 2 años459 visualizaciones
1 Respuesta

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas