-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add url(protocol) validation to add callback mutation (#3513)
- Loading branch information
Showing
5 changed files
with
54 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,32 @@ | ||
import { URL } from "url" | ||
|
||
import { GT } from "@/graphql/index" | ||
import { InputValidationError } from "@/graphql/error" | ||
|
||
const EndpointUrl = GT.Scalar({ | ||
name: "EndpointUrl", | ||
description: "Url that will be fetched on events for the account", | ||
serialize(value) { | ||
if (typeof value !== "string") { | ||
return "Invalid value for EndpointUrl" | ||
parseValue(value) { | ||
if (typeof value === "string") { | ||
return validUrlValue(value) | ||
} | ||
return value | ||
return new InputValidationError({ message: "Invalid type for EndpointUrl" }) | ||
}, | ||
parseLiteral(ast) { | ||
if (ast.kind === GT.Kind.STRING) { | ||
return validUrlValue(ast.value) | ||
} | ||
return new InputValidationError({ message: "Invalid type for EndpointUrl" }) | ||
}, | ||
}) | ||
|
||
function validUrlValue(value: string) { | ||
try { | ||
new URL(value) | ||
return value | ||
} catch (error) { | ||
return new InputValidationError({ message: "Invalid value for EndpointUrl" }) | ||
} | ||
} | ||
|
||
export default EndpointUrl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters