question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does the GraphQL Transformer support Subscriptions with arguments?

See original GitHub issue

** Which Category is your question related to? ** GraphQL Transformer, VTL

** What AWS Services are you utilizing? ** AppSync

** Provide additional details e.g. code snippets ** Is there a way to create a subscription that accepts specific arguments in the annotated schema? Such as a subscription for comments on a particular Blog post:

type Subscription {

   onCreateComment(postId: ID!) @aws_subscribe(mutations: ["createComment"])

}

And if not yet supported, is there a way to add it as a “pass-thru” so it ends up in the final schema? Currently adding it and running Amplify push deletes it from the annotated schema, not sure if that is by design or is a defect.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
Floscommented, Oct 9, 2019

Im also a bit lost here. So codegen creates code which is not working when you need an argument as owner for a subscription or? Or how can I pass the owner as input to the subscription in Angular with the generated code?

amplify --version --> 3.0.0

1reaction
RidClickcommented, Mar 11, 2019

I need some help here. The APIService generated by codegen has generated this function.

SubscribeToNewMessageListener: Observable<SubscribeToNewMessageSubscription> = API.graphql(
    graphqlOperation(
      `subscription SubscribeToNewMessage($conversationId: ID!) {
        subscribeToNewMessage(conversationId: $conversationId) {
          __typename
          author {
            __typename
            cognitoId
            id
            username
            registered
          }
          content
          conversationId
          createdAt
          id
          isSent
          recipient {
            __typename
            cognitoId
            id
            username
            registered
          }
          sender
        }
      }`
    )
  ) as Observable<SubscribeToNewMessageSubscription>;

I’m trying to call this listener from an angular page but I can not pass the parameter to the function always get “Variable ‘conversationId’ has coerced Null value for NonNull type ‘ID!’”. I have tried in all ways but I can not send it.

This is more or less my code.

constructor(
        private api: APIService
    ) {}

    ngOnInit() {
        this.api.SubscribeToNewMessageListener
        .map(msg => msg.conversationId = 'randomGUID')
        .subscribe({
            next: (x) => {console.log('Next',x)},
            error: (e) => {console.log('Error', e)},
            complete: () => {}
        })
    }

Another subscription without parameters, however, it works for me simply by subscribing to it.

Please need help. Thanks you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

API (GraphQL) - Examples - AWS Amplify Docs
Add the subscriptions argument on the @model directive, telling Amplify to not generate subscriptions for your Comment type.
Read more >
Filtering GraphQL Subscriptions with Arguments with AWS ...
When working with real-time data in GraphQL, a very common use case is the need to filter subscriptions based on arguments (think about...
Read more >
API Reference: graphql-tools - Apollo GraphQL Docs
The graphql-tools library enables the creation and manipulation of GraphQL schema. Apollo Server is able to accept a schema that has been enabled...
Read more >
How to use the graphql-transformer-core.getDirectiveArguments ...
To help you get started, we've selected a few graphql-transformer-core. ... Check if subscriptions is enabled const directiveArguments: ModelDirectiveArgs ...
Read more >
AWS Amplify announces the new GraphQL Transformer v2 ...
With the Transformer, developers can configure their backend data model using the GraphQL Schema Definition Language, and Amplify CLI ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found