Search code examples
graphqlamazon-cognitoaws-amplifyaws-appsyncreact-typescript

Amplify/React AppSync graphql subscriptions @auth error


Hello there :slight_smile:

I've a little problem related with the @auth. (Amplify + React + AppSync)

schema.graphql

type Ticket @model
@auth(rules: [
  {allow: owner, provider: userPools},
])
{
  id: ID!
  status: String!
  owner: String!
  description: String!
}

build -> schema.graphql

type Subscription {
  onCreateTicket(owner: String!): Ticket @aws_subscribe(mutations: ["createTicket"])
  onUpdateTicket(owner: String!): Ticket @aws_subscribe(mutations: ["updateTicket"])
  onDeleteTicket(owner: String!): Ticket @aws_subscribe(mutations: ["deleteTicket"])
}

All operations (create update etc.) are working fine:

const {data: {listTickets: {items: items, nextToken}}} = await API
                .graphql(graphqlOperation(listTickets, {
                    owner: user.username                    
                })) as GraphQLResult;

except with subscriptions:

const subClient = API
  .graphql(graphqlOperation(onUpdateTicket, {
                    owner: user.username
})) as Observable<object>;    

subscription = subClient.subscribe({
                next: (data: any) => console.log('subscription data:', data),
                error: error => console.warn('subscription error: ', error)
            });

The subscription never trigger. (No errors, no warnings)

Any help would be much appreciated!

Thanks


Solution

  • Screenshot

    It was working!!! I forgot to check "owner" not only in the input* but also in the fields below.

    #aws-amplify-devs Could you please add this info to the documentation? :) Could save many hours.