Input validation with AWS AppSync
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
add a comment |
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
add a comment |
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
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
amazon-web-services graphql aws-appsync
asked Nov 20 '18 at 7:25
Samuel E.Samuel E.
6212716
6212716
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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