aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.43k stars 2.13k forks source link

AppSync - Subscription with type [String] different behavior in Amplify and AWS console 'Query' IDE. #1327

Closed tandeson closed 6 years ago

tandeson commented 6 years ago

Do you want to request a feature or report a bug? I think this is a bug - however, I can't find the behavior clearly documented in the GraphQL docs - so it may be a feature.

What is the current behavior? Subscriptions with a item filter of [String] behave differently in AWS Console and AWS Amplify. In the AWS Console, I get events when I listen with a string into a list of strings, and in Amplify I do not get any returned data.

I have a server Scheme which passes message in a 1-to-many format.

I would like to subscribe so that only the receive gets a message ( so the data type has a list of strings, but only subscribe if you match one of them).

Part of the server side schema

input StartCallInput {
    from_user_id: String!
    from_user_username: String!
    to_user_ids: [String]!
    call_type: CallType!
}

type StartCallResponse {
    session_id: String!
    token: String
    from_user_id: String
    to_user_id: [String]
    from_bolt_user: String
    call_type: String
}

type Mutation {
    startCall(input: StartCallInput!): StartCallResponse
}

type Subscription {
    onCallStarted(to_user_id: [String], from_user_id: String): StartCallResponse
        @aws_subscribe(mutations: ["startCall"])
}

What is the expected behavior? In the AWS Console IDE the subscription below returned the record when tested with a list with 7d0773ff-2c48-412c-a6e0-0eb275f2fa73 present

subscription watchForNewCalls {
  onCallStarted(to_user_id:"7d0773ff-2c48-412c-a6e0-0eb275f2fa73") {
    session_id
    token
    from_user_id
    to_user_id
    from_bolt_user
    call_type
  }
}

Note that passing in a list of one item also worked

 onCallStarted(to_user_id:["7d0773ff-2c48-412c-a6e0-0eb275f2fa73"])

In my Angular 6.0 App, using Angular Amplify - I could not get any subscription responses with this list item (see code snippets below). When I filtered on from_user_id instead ( a String not a [String] ), the returned data was as expected.

Function to call AWS Amplify AppSync

// Generic Start Subscription call ( note the Zen Observable instead of a RxJs Observable)
  appSyncStartSubscription( subscriptionCall: String, ParameterValues?: any ): Observable<object> {
    return API.graphql( graphqlOperation( subscriptionCall, ParameterValues ) ) as Observable<object>;
  }

passing in for Subscription

export const SubscribeToEventNewDevices = `subscription watchForNewCalls( $to_user_id: [String]) {
  onCallStarted( to_user_id:$to_user_id ) {
    session_id
    token
    from_user_id
    to_user_id
    from_bolt_user
    call_type
  }
}`;

and data is

    const myIdInfo  = {
       to_user_id: '7d0773ff-2c48-412c-a6e0-0eb275f2fa73',
    };

I have also tried

    const myIdInfo  = {
       to_user_id: ['7d0773ff-2c48-412c-a6e0-0eb275f2fa73'],
    };

Which versions of Amplify, and which browser / OS are affected by this issue? Did this work in previous versions? I am using Firefox 61.0.1 (64-bit) on Windows 10

ng --version

Angular CLI: 6.0.7 Node: 8.9.1 OS: win32 x64 Angular: 6.0.3 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.6.7 @angular-devkit/build-angular 0.6.8 @angular-devkit/build-optimizer 0.6.8 @angular-devkit/core 0.6.7 @angular-devkit/schematics 0.6.7 @angular/cdk 6.4.1 @angular/cli 6.0.7 @angular/flex-layout 5.0.0-beta.15 @angular/material 6.4.1 @ngtools/webpack 6.0.8 @schematics/angular 0.6.7 @schematics/update 0.6.7 rxjs 6.2.2 typescript 2.7.2 webpack 4.8.3

npm ls aws-amplify -- aws-amplify@1.0.2

manueliglesias commented 6 years ago

Hi @tandeson Can you share the network request when the subscription is made?

tandeson commented 6 years ago

Sorry - I should have closed this. I came in on Monday and it all worked. I think something was happening on the AppSync back end. No code changes on my side, and I no longer can re-create this issue. I can re-open if it happen again, and I'll capture the network request, but again - I don't think this is in the Amplify library at this time.

jordanranz commented 6 years ago

Hey @tandeson, I am going to close this as per your comment above. Please reopen if you are still having an issue.

github-actions[bot] commented 3 years ago

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.