Input validation with AWS AppSync












0















Is it possible to do input validation with AWS AppSync without adding another "layer" of interaction?
I feel like adding a lambada function will defeat the purpose of it.
What I Would like to accomplish is at least some regexp validation on strings.



And if not, then how do people that use AppSync or similar solutions(firebase) do so?










share|improve this question



























    0















    Is it possible to do input validation with AWS AppSync without adding another "layer" of interaction?
    I feel like adding a lambada function will defeat the purpose of it.
    What I Would like to accomplish is at least some regexp validation on strings.



    And if not, then how do people that use AppSync or similar solutions(firebase) do so?










    share|improve this question

























      0












      0








      0








      Is it possible to do input validation with AWS AppSync without adding another "layer" of interaction?
      I feel like adding a lambada function will defeat the purpose of it.
      What I Would like to accomplish is at least some regexp validation on strings.



      And if not, then how do people that use AppSync or similar solutions(firebase) do so?










      share|improve this question














      Is it possible to do input validation with AWS AppSync without adding another "layer" of interaction?
      I feel like adding a lambada function will defeat the purpose of it.
      What I Would like to accomplish is at least some regexp validation on strings.



      And if not, then how do people that use AppSync or similar solutions(firebase) do so?







      amazon-web-services graphql aws-appsync






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 7:25









      Samuel E.Samuel E.

      6212716




      6212716
























          1 Answer
          1






          active

          oldest

          votes


















          2














          If it's only regex validation without having to check the input against data in a data source, then you can prepend some validation logic inside the resolver request mapping template.



          See below an example for checking if the input field matches is an email from the myvaliddomain.com. If it doesn't validate, we just abort and error the field.



          #set($valid = $util.matches("^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+.)?[a-zA-Z]+.)?(myvaliddomain).com", $ctx.args.input))
          #if (!$valid)
          $util.error("$ctx.args.input is not a valid email.", "ValidationError")
          #end

          ## Rest of your request mapping template below





          share|improve this answer
























          • Thank you, that is what I was looking for. One more question if you don't mind: Since the first argument to $util.matches is a string, would it be possible to grab that Regex pattern from the Database itself?

            – Samuel E.
            Nov 20 '18 at 18:10











          • Since you now have to wire multiple datasources to a single GraphQL field, you can use a pipeline resolver. Your pipeline resolver would be comprised of two functions, the first function would retrieve the regex pattern from say DynamoDB using a GetItem operation and do the validation inside the response mapping template, and the second function would actually run another operation only if the first function succeeds. Check out docs.aws.amazon.com/appsync/latest/devguide/… for a complete explanation.

            – Tinou
            Nov 20 '18 at 23:49











          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%2f53388115%2finput-validation-with-aws-appsync%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          If it's only regex validation without having to check the input against data in a data source, then you can prepend some validation logic inside the resolver request mapping template.



          See below an example for checking if the input field matches is an email from the myvaliddomain.com. If it doesn't validate, we just abort and error the field.



          #set($valid = $util.matches("^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+.)?[a-zA-Z]+.)?(myvaliddomain).com", $ctx.args.input))
          #if (!$valid)
          $util.error("$ctx.args.input is not a valid email.", "ValidationError")
          #end

          ## Rest of your request mapping template below





          share|improve this answer
























          • Thank you, that is what I was looking for. One more question if you don't mind: Since the first argument to $util.matches is a string, would it be possible to grab that Regex pattern from the Database itself?

            – Samuel E.
            Nov 20 '18 at 18:10











          • Since you now have to wire multiple datasources to a single GraphQL field, you can use a pipeline resolver. Your pipeline resolver would be comprised of two functions, the first function would retrieve the regex pattern from say DynamoDB using a GetItem operation and do the validation inside the response mapping template, and the second function would actually run another operation only if the first function succeeds. Check out docs.aws.amazon.com/appsync/latest/devguide/… for a complete explanation.

            – Tinou
            Nov 20 '18 at 23:49
















          2














          If it's only regex validation without having to check the input against data in a data source, then you can prepend some validation logic inside the resolver request mapping template.



          See below an example for checking if the input field matches is an email from the myvaliddomain.com. If it doesn't validate, we just abort and error the field.



          #set($valid = $util.matches("^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+.)?[a-zA-Z]+.)?(myvaliddomain).com", $ctx.args.input))
          #if (!$valid)
          $util.error("$ctx.args.input is not a valid email.", "ValidationError")
          #end

          ## Rest of your request mapping template below





          share|improve this answer
























          • Thank you, that is what I was looking for. One more question if you don't mind: Since the first argument to $util.matches is a string, would it be possible to grab that Regex pattern from the Database itself?

            – Samuel E.
            Nov 20 '18 at 18:10











          • Since you now have to wire multiple datasources to a single GraphQL field, you can use a pipeline resolver. Your pipeline resolver would be comprised of two functions, the first function would retrieve the regex pattern from say DynamoDB using a GetItem operation and do the validation inside the response mapping template, and the second function would actually run another operation only if the first function succeeds. Check out docs.aws.amazon.com/appsync/latest/devguide/… for a complete explanation.

            – Tinou
            Nov 20 '18 at 23:49














          2












          2








          2







          If it's only regex validation without having to check the input against data in a data source, then you can prepend some validation logic inside the resolver request mapping template.



          See below an example for checking if the input field matches is an email from the myvaliddomain.com. If it doesn't validate, we just abort and error the field.



          #set($valid = $util.matches("^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+.)?[a-zA-Z]+.)?(myvaliddomain).com", $ctx.args.input))
          #if (!$valid)
          $util.error("$ctx.args.input is not a valid email.", "ValidationError")
          #end

          ## Rest of your request mapping template below





          share|improve this answer













          If it's only regex validation without having to check the input against data in a data source, then you can prepend some validation logic inside the resolver request mapping template.



          See below an example for checking if the input field matches is an email from the myvaliddomain.com. If it doesn't validate, we just abort and error the field.



          #set($valid = $util.matches("^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+.)?[a-zA-Z]+.)?(myvaliddomain).com", $ctx.args.input))
          #if (!$valid)
          $util.error("$ctx.args.input is not a valid email.", "ValidationError")
          #end

          ## Rest of your request mapping template below






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 '18 at 18:04









          TinouTinou

          4,05941319




          4,05941319













          • Thank you, that is what I was looking for. One more question if you don't mind: Since the first argument to $util.matches is a string, would it be possible to grab that Regex pattern from the Database itself?

            – Samuel E.
            Nov 20 '18 at 18:10











          • Since you now have to wire multiple datasources to a single GraphQL field, you can use a pipeline resolver. Your pipeline resolver would be comprised of two functions, the first function would retrieve the regex pattern from say DynamoDB using a GetItem operation and do the validation inside the response mapping template, and the second function would actually run another operation only if the first function succeeds. Check out docs.aws.amazon.com/appsync/latest/devguide/… for a complete explanation.

            – Tinou
            Nov 20 '18 at 23:49



















          • Thank you, that is what I was looking for. One more question if you don't mind: Since the first argument to $util.matches is a string, would it be possible to grab that Regex pattern from the Database itself?

            – Samuel E.
            Nov 20 '18 at 18:10











          • Since you now have to wire multiple datasources to a single GraphQL field, you can use a pipeline resolver. Your pipeline resolver would be comprised of two functions, the first function would retrieve the regex pattern from say DynamoDB using a GetItem operation and do the validation inside the response mapping template, and the second function would actually run another operation only if the first function succeeds. Check out docs.aws.amazon.com/appsync/latest/devguide/… for a complete explanation.

            – Tinou
            Nov 20 '18 at 23:49

















          Thank you, that is what I was looking for. One more question if you don't mind: Since the first argument to $util.matches is a string, would it be possible to grab that Regex pattern from the Database itself?

          – Samuel E.
          Nov 20 '18 at 18:10





          Thank you, that is what I was looking for. One more question if you don't mind: Since the first argument to $util.matches is a string, would it be possible to grab that Regex pattern from the Database itself?

          – Samuel E.
          Nov 20 '18 at 18:10













          Since you now have to wire multiple datasources to a single GraphQL field, you can use a pipeline resolver. Your pipeline resolver would be comprised of two functions, the first function would retrieve the regex pattern from say DynamoDB using a GetItem operation and do the validation inside the response mapping template, and the second function would actually run another operation only if the first function succeeds. Check out docs.aws.amazon.com/appsync/latest/devguide/… for a complete explanation.

          – Tinou
          Nov 20 '18 at 23:49





          Since you now have to wire multiple datasources to a single GraphQL field, you can use a pipeline resolver. Your pipeline resolver would be comprised of two functions, the first function would retrieve the regex pattern from say DynamoDB using a GetItem operation and do the validation inside the response mapping template, and the second function would actually run another operation only if the first function succeeds. Check out docs.aws.amazon.com/appsync/latest/devguide/… for a complete explanation.

          – Tinou
          Nov 20 '18 at 23:49


















          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%2f53388115%2finput-validation-with-aws-appsync%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

          'app-layout' is not a known element: how to share Component with different Modules

          android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

          WPF add header to Image with URL pettitions [duplicate]