Generate Subscription with arguments in AWS AppSync with GraphQL Transform












0















I’m currently using GraphQL transform lib to generate all my schema.
I have a model defined like this:



type Feedback @model {
id: ID!
event: Event! @connection(name: "EventFeedbacks")
submittedDate: AWSDateTime!
}


and the auto-generated subscription schema is like this:



type Subscription {
onCreateFeedback: Feedback
@aws_subscribe(mutations: ["createFeedback"])
}


I would like to have an argument for the subscription so that I can subscribe to that event only, like this:



type Subscription {
onCreateFeedback(eventId: ID): Feedback
@aws_subscribe(mutations: ["createFeedback"])
}


What do I need to do to get this subscription auto generated? Thanks!










share|improve this question



























    0















    I’m currently using GraphQL transform lib to generate all my schema.
    I have a model defined like this:



    type Feedback @model {
    id: ID!
    event: Event! @connection(name: "EventFeedbacks")
    submittedDate: AWSDateTime!
    }


    and the auto-generated subscription schema is like this:



    type Subscription {
    onCreateFeedback: Feedback
    @aws_subscribe(mutations: ["createFeedback"])
    }


    I would like to have an argument for the subscription so that I can subscribe to that event only, like this:



    type Subscription {
    onCreateFeedback(eventId: ID): Feedback
    @aws_subscribe(mutations: ["createFeedback"])
    }


    What do I need to do to get this subscription auto generated? Thanks!










    share|improve this question

























      0












      0








      0








      I’m currently using GraphQL transform lib to generate all my schema.
      I have a model defined like this:



      type Feedback @model {
      id: ID!
      event: Event! @connection(name: "EventFeedbacks")
      submittedDate: AWSDateTime!
      }


      and the auto-generated subscription schema is like this:



      type Subscription {
      onCreateFeedback: Feedback
      @aws_subscribe(mutations: ["createFeedback"])
      }


      I would like to have an argument for the subscription so that I can subscribe to that event only, like this:



      type Subscription {
      onCreateFeedback(eventId: ID): Feedback
      @aws_subscribe(mutations: ["createFeedback"])
      }


      What do I need to do to get this subscription auto generated? Thanks!










      share|improve this question














      I’m currently using GraphQL transform lib to generate all my schema.
      I have a model defined like this:



      type Feedback @model {
      id: ID!
      event: Event! @connection(name: "EventFeedbacks")
      submittedDate: AWSDateTime!
      }


      and the auto-generated subscription schema is like this:



      type Subscription {
      onCreateFeedback: Feedback
      @aws_subscribe(mutations: ["createFeedback"])
      }


      I would like to have an argument for the subscription so that I can subscribe to that event only, like this:



      type Subscription {
      onCreateFeedback(eventId: ID): Feedback
      @aws_subscribe(mutations: ["createFeedback"])
      }


      What do I need to do to get this subscription auto generated? Thanks!







      aws-appsync graphql-subscriptions






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 19 at 8:55









      odieatlaodieatla

      3552723




      3552723
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Customizing the subscription fields arguments is currently not supported. The only supported customization is to create multiple subscription fields tied to a single mutation.



          Example:



          type Feedback @model(subscriptions: { onCreate: ["onCreateFeedback", "onCreateFeedbackById"] }) {
          id: ID!
          event: Event! @connection(name: "EventFeedbacks")
          submittedDate: AWSDateTime!
          }


          will generate for the subscription type:



          type Subscription {
          onCreateFeedback: Feedback
          @aws_subscribe(mutations: ["createFeedback"])
          onCreateFeedbackById: Feedback
          @aws_subscribe(mutations: ["createFeedback"])
          }


          but then you will have to add the eventId argument manually on the onCreateFeedbackById field.



          Though, I would suggest to open a feature request in https://github.com/aws-amplify/amplify-cli/issues






          share|improve this answer































            1














            As @Tinou correctly outlines, you can rename and turn off subscription fields that are generated by @model using the subscriptions arg but you also the ability to create custom subscriptions by adding a Subscription type to your schema.



            type Subscription {
            customField(arg: String): String @aws_subscribe(mutations:["customPublish"])
            }


            With this approach, you can add any fields and arguments that you need.






            share|improve this answer
























            • Before I was having error message like 'unknown directive @aws_subscribe'. Now I can compile after I switch to multienv branch of @aws-amplify/cli. Now the subscription with argument can be generated now, but no result is received after a mutation. Do I need to write a resolver for the subscription?

              – odieatla
              Jan 22 at 19:00











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265505%2fgenerate-subscription-with-arguments-in-aws-appsync-with-graphql-transform%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Customizing the subscription fields arguments is currently not supported. The only supported customization is to create multiple subscription fields tied to a single mutation.



            Example:



            type Feedback @model(subscriptions: { onCreate: ["onCreateFeedback", "onCreateFeedbackById"] }) {
            id: ID!
            event: Event! @connection(name: "EventFeedbacks")
            submittedDate: AWSDateTime!
            }


            will generate for the subscription type:



            type Subscription {
            onCreateFeedback: Feedback
            @aws_subscribe(mutations: ["createFeedback"])
            onCreateFeedbackById: Feedback
            @aws_subscribe(mutations: ["createFeedback"])
            }


            but then you will have to add the eventId argument manually on the onCreateFeedbackById field.



            Though, I would suggest to open a feature request in https://github.com/aws-amplify/amplify-cli/issues






            share|improve this answer




























              1














              Customizing the subscription fields arguments is currently not supported. The only supported customization is to create multiple subscription fields tied to a single mutation.



              Example:



              type Feedback @model(subscriptions: { onCreate: ["onCreateFeedback", "onCreateFeedbackById"] }) {
              id: ID!
              event: Event! @connection(name: "EventFeedbacks")
              submittedDate: AWSDateTime!
              }


              will generate for the subscription type:



              type Subscription {
              onCreateFeedback: Feedback
              @aws_subscribe(mutations: ["createFeedback"])
              onCreateFeedbackById: Feedback
              @aws_subscribe(mutations: ["createFeedback"])
              }


              but then you will have to add the eventId argument manually on the onCreateFeedbackById field.



              Though, I would suggest to open a feature request in https://github.com/aws-amplify/amplify-cli/issues






              share|improve this answer


























                1












                1








                1







                Customizing the subscription fields arguments is currently not supported. The only supported customization is to create multiple subscription fields tied to a single mutation.



                Example:



                type Feedback @model(subscriptions: { onCreate: ["onCreateFeedback", "onCreateFeedbackById"] }) {
                id: ID!
                event: Event! @connection(name: "EventFeedbacks")
                submittedDate: AWSDateTime!
                }


                will generate for the subscription type:



                type Subscription {
                onCreateFeedback: Feedback
                @aws_subscribe(mutations: ["createFeedback"])
                onCreateFeedbackById: Feedback
                @aws_subscribe(mutations: ["createFeedback"])
                }


                but then you will have to add the eventId argument manually on the onCreateFeedbackById field.



                Though, I would suggest to open a feature request in https://github.com/aws-amplify/amplify-cli/issues






                share|improve this answer













                Customizing the subscription fields arguments is currently not supported. The only supported customization is to create multiple subscription fields tied to a single mutation.



                Example:



                type Feedback @model(subscriptions: { onCreate: ["onCreateFeedback", "onCreateFeedbackById"] }) {
                id: ID!
                event: Event! @connection(name: "EventFeedbacks")
                submittedDate: AWSDateTime!
                }


                will generate for the subscription type:



                type Subscription {
                onCreateFeedback: Feedback
                @aws_subscribe(mutations: ["createFeedback"])
                onCreateFeedbackById: Feedback
                @aws_subscribe(mutations: ["createFeedback"])
                }


                but then you will have to add the eventId argument manually on the onCreateFeedbackById field.



                Though, I would suggest to open a feature request in https://github.com/aws-amplify/amplify-cli/issues







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 19 at 23:50









                TinouTinou

                4,13441319




                4,13441319

























                    1














                    As @Tinou correctly outlines, you can rename and turn off subscription fields that are generated by @model using the subscriptions arg but you also the ability to create custom subscriptions by adding a Subscription type to your schema.



                    type Subscription {
                    customField(arg: String): String @aws_subscribe(mutations:["customPublish"])
                    }


                    With this approach, you can add any fields and arguments that you need.






                    share|improve this answer
























                    • Before I was having error message like 'unknown directive @aws_subscribe'. Now I can compile after I switch to multienv branch of @aws-amplify/cli. Now the subscription with argument can be generated now, but no result is received after a mutation. Do I need to write a resolver for the subscription?

                      – odieatla
                      Jan 22 at 19:00
















                    1














                    As @Tinou correctly outlines, you can rename and turn off subscription fields that are generated by @model using the subscriptions arg but you also the ability to create custom subscriptions by adding a Subscription type to your schema.



                    type Subscription {
                    customField(arg: String): String @aws_subscribe(mutations:["customPublish"])
                    }


                    With this approach, you can add any fields and arguments that you need.






                    share|improve this answer
























                    • Before I was having error message like 'unknown directive @aws_subscribe'. Now I can compile after I switch to multienv branch of @aws-amplify/cli. Now the subscription with argument can be generated now, but no result is received after a mutation. Do I need to write a resolver for the subscription?

                      – odieatla
                      Jan 22 at 19:00














                    1












                    1








                    1







                    As @Tinou correctly outlines, you can rename and turn off subscription fields that are generated by @model using the subscriptions arg but you also the ability to create custom subscriptions by adding a Subscription type to your schema.



                    type Subscription {
                    customField(arg: String): String @aws_subscribe(mutations:["customPublish"])
                    }


                    With this approach, you can add any fields and arguments that you need.






                    share|improve this answer













                    As @Tinou correctly outlines, you can rename and turn off subscription fields that are generated by @model using the subscriptions arg but you also the ability to create custom subscriptions by adding a Subscription type to your schema.



                    type Subscription {
                    customField(arg: String): String @aws_subscribe(mutations:["customPublish"])
                    }


                    With this approach, you can add any fields and arguments that you need.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 21 at 19:19









                    mparismparis

                    1,68676




                    1,68676













                    • Before I was having error message like 'unknown directive @aws_subscribe'. Now I can compile after I switch to multienv branch of @aws-amplify/cli. Now the subscription with argument can be generated now, but no result is received after a mutation. Do I need to write a resolver for the subscription?

                      – odieatla
                      Jan 22 at 19:00



















                    • Before I was having error message like 'unknown directive @aws_subscribe'. Now I can compile after I switch to multienv branch of @aws-amplify/cli. Now the subscription with argument can be generated now, but no result is received after a mutation. Do I need to write a resolver for the subscription?

                      – odieatla
                      Jan 22 at 19:00

















                    Before I was having error message like 'unknown directive @aws_subscribe'. Now I can compile after I switch to multienv branch of @aws-amplify/cli. Now the subscription with argument can be generated now, but no result is received after a mutation. Do I need to write a resolver for the subscription?

                    – odieatla
                    Jan 22 at 19:00





                    Before I was having error message like 'unknown directive @aws_subscribe'. Now I can compile after I switch to multienv branch of @aws-amplify/cli. Now the subscription with argument can be generated now, but no result is received after a mutation. Do I need to write a resolver for the subscription?

                    – odieatla
                    Jan 22 at 19:00


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54265505%2fgenerate-subscription-with-arguments-in-aws-appsync-with-graphql-transform%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Callistus III

                    Ostreoida

                    Plistias Cous