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.

질문됨 2년 전459회 조회
1개 답변

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠