Skip to content

feat: allow additional parser options in the gradle and maven plugins #1925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@
<parserOptions>
<maxTokens>15000</maxTokens>
<maxWhitespaceTokens>200000</maxWhitespaceTokens>
<maxCharacters>1048576</maxCharacters>
<maxRuleDepth>500</maxRuleDepth>
<captureIgnoredChars>false</captureIgnoredChars>
<captureLineComments>false</captureLineComments>
<captureSourceLocation>true</captureSourceLocation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ abstract class GenerateClientAction : WorkAction<GenerateClientParameters> {
parserOptions = {
parserOptions.maxTokens?.let { maxTokens(it) }
parserOptions.maxWhitespaceTokens?.let { maxWhitespaceTokens(it) }
parserOptions.maxCharacters?.let { maxCharacters(it) }
parserOptions.maxRuleDepth?.let { maxRuleDepth(it) }
parserOptions.captureIgnoredChars?.let { captureIgnoredChars(it) }
parserOptions.captureSourceLocation?.let { captureSourceLocation(it) }
parserOptions.captureLineComments?.let { captureLineComments(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ data class GraphQLParserOptions(
var maxTokens: Int? = null,
/** Modify the maximum number of whitespace tokens read to prevent processing extremely large queries */
var maxWhitespaceTokens: Int? = null,
/** Modify the maximum number of characters in a document to prevent malicious documents consuming CPU */
val maxCharacters: Int? = null,
/** Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows */
val maxRuleDepth: Int? = null,
/** Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing. */
var captureIgnoredChars: Boolean? = null,
/** Single-line comments do not have any semantic meaning in GraphQL source documents and can be ignored */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ abstract class GenerateClientAbstractMojo : AbstractMojo() {
* <parserOptions>
* <maxTokens>15000</maxTokens>
* <maxWhitespaceTokens>200000</maxWhitespaceTokens>
* <maxCharacters>1048576</maxCharacters>
* <maxRuleDepth>500</maxRuleDepth>
* <captureIgnoredChars>false</captureIgnoredChars>
* <captureLineComments>false</captureLineComments>
* <captureSourceLocation>true</captureSourceLocation>
Expand Down Expand Up @@ -137,6 +139,8 @@ abstract class GenerateClientAbstractMojo : AbstractMojo() {
parserOptions?.apply {
maxTokens?.let { maxTokens(it) }
maxWhitespaceTokens?.let { maxWhitespaceTokens(it) }
maxCharacters?.let { maxCharacters(it) }
maxRuleDepth?.let { maxRuleDepth(it) }
captureIgnoredChars?.let { captureIgnoredChars(it) }
captureLineComments?.let { captureLineComments(it) }
captureSourceLocation?.let { captureSourceLocation(it) }
Expand Down Expand Up @@ -178,6 +182,8 @@ abstract class GenerateClientAbstractMojo : AbstractMojo() {
log.debug(" parserOptions")
maxTokens?.let { log.debug(" maxTokens = $it") }
maxWhitespaceTokens?.let { log.debug(" maxWhitespaceTokens = $it") }
maxCharacters?.let { log.debug(" maxCharacters = $it") }
maxRuleDepth?.let { log.debug(" maxRuleDepth = $it") }
captureIgnoredChars?.let { log.debug(" captureIgnoredChars = $it") }
captureLineComments?.let { log.debug(" captureLineComments = $it") }
captureSourceLocation?.let { log.debug(" captureSourceLocation = $it") }
Expand Down Expand Up @@ -224,6 +230,14 @@ class ParserOptions {
@Parameter
var maxWhitespaceTokens: Int? = null

/** Modify the maximum number of characters in a document to prevent malicious documents consuming CPU */
@Parameter
val maxCharacters: Int? = null

/** Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows */
@Parameter
val maxRuleDepth: Int? = null

/** Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing. */
@Parameter
var captureIgnoredChars: Boolean? = null
Expand Down
16 changes: 16 additions & 0 deletions website/docs/plugins/gradle-plugin-tasks.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ graphql {
maxTokens = 15000
// Override the maximum number of whitespace tokens read to prevent processing extremely large queries.
maxWhitespaceTokens = 200000
// Modify the maximum number of characters in a document to prevent malicious documents consuming CPU
maxCharacters = 1048576
// Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows
maxRuleDepth = 500
// Single-line comments do not have any semantic meaning in GraphQL source documents and can be ignored
captureLineComments = false
// Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing.
Expand Down Expand Up @@ -213,6 +217,10 @@ graphql {
options.maxTokens = 15000
// Override the maximum number of whitespace tokens read to prevent processing extremely large queries.
options.maxWhitespaceTokens = 200000
// Modify the maximum number of characters in a document to prevent malicious documents consuming CPU
options.maxCharacters = 1048576
// Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows
options.maxRuleDepth = 500
// Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing.
options.captureIgnoredChars = false
// Memory usage is reduced by not setting SourceLocations on AST nodes, especially in SDL parsing.
Expand Down Expand Up @@ -318,6 +326,10 @@ for details on how to update this process to use `kotlinx.serialization` instead
maxTokens = 15000
// Override the maximum number of whitespace tokens read to prevent processing extremely large queries.
maxWhitespaceTokens = 200000
// Modify the maximum number of characters in a document to prevent malicious documents consuming CPU
maxCharacters = 1048576
// Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows
maxRuleDepth = 500
// Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing.
captureIgnoredChars = false
// Memory usage is reduced by not setting SourceLocations on AST nodes, especially in SDL parsing.
Expand Down Expand Up @@ -388,6 +400,10 @@ for details on how to update this process to use `kotlinx.serialization` instead
maxTokens = 15000
// Override the maximum number of whitespace tokens read to prevent processing extremely large queries.
maxWhitespaceTokens = 200000
// Modify the maximum number of characters in a document to prevent malicious documents consuming CPU
maxCharacters = 1048576
// Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows
maxRuleDepth = 500
// Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing.
captureIgnoredChars = false
// Memory usage is reduced by not setting SourceLocations on AST nodes, especially in SDL parsing.
Expand Down
8 changes: 8 additions & 0 deletions website/docs/plugins/maven-plugin-goals.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ Generate GraphQL client code based on the provided GraphQL schema and target que
<maxTokens>15000</maxTokens>
<!-- Modify the maximum number of whitespace tokens read to prevent processing extremely large queries -->
<maxWhitespaceTokens>200000</maxWhitespaceTokens>
<!-- Modify the maximum number of characters in a document to prevent malicious documents consuming CPU -->
<maxCharacters>1048576</maxCharacters>
<!-- Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows -->
<maxRuleDepth>500</maxRuleDepth>
<!-- Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing -->
<captureIgnoredChars>false</captureIgnoredChars>
<!-- Single-line comments do not have any semantic meaning in GraphQL source documents and can be ignored -->
Expand Down Expand Up @@ -209,6 +213,10 @@ Generate GraphQL test client code based on the provided GraphQL schema and targe
<maxTokens>15000</maxTokens>
<!-- Modify the maximum number of whitespace tokens read to prevent processing extremely large queries -->
<maxWhitespaceTokens>200000</maxWhitespaceTokens>
<!-- Modify the maximum number of characters in a document to prevent malicious documents consuming CPU -->
<maxCharacters>1048576</maxCharacters>
<!-- Modify the maximum grammar rule depth to negate malicious documents that can cause stack overflows -->
<maxRuleDepth>500</maxRuleDepth>
<!-- Memory usage is significantly reduced by not capturing ignored characters, especially in SDL parsing -->
<captureIgnoredChars>false</captureIgnoredChars>
<!-- Single-line comments do not have any semantic meaning in GraphQL source documents and can be ignored -->
Expand Down