-
Notifications
You must be signed in to change notification settings - Fork 14
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
feature: Add variable validation rule to query save #249
Closed
markkelnar
wants to merge
11
commits into
wp-graphql:main
from
markkelnar:fix/enforce-arguments-as-variables
Closed
Changes from 7 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7465ec6
Add variable validation rule to query save
markkelnar 4c6d9ca
that seems impossible
markkelnar a0df80c
Merge remote-tracking branch 'origin/main' into fix/enforce-arguments…
markkelnar 11054c0
white space removal
markkelnar c2fab42
fix some invalid queries in tests :)
markkelnar a8cff50
Merge remote-tracking branch 'origin/main' into fix/enforce-arguments…
markkelnar f82ef35
update tests to pa^C node type as variable
markkelnar 35a911e
Add IntVal as argument type to invalidate
markkelnar 3c7b649
Interogate where() clause in query for variables
markkelnar 25699b6
Fix the test expectation message
markkelnar 22d8717
when argument is of type object value
markkelnar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
|
||
namespace WPGraphQL\SmartCache\ValidationRules; | ||
|
||
use GraphQL\Error\Error; | ||
use GraphQL\Language\AST\NodeKind; | ||
use GraphQL\Language\AST\ArgumentNode; | ||
use GraphQL\Validator\Rules\ValidationRule; | ||
use GraphQL\Validator\ValidationContext; | ||
|
||
/** | ||
* Class ArgShouldBeVariable | ||
* | ||
* @package WPGraphQL\SmartCache\Rules | ||
*/ | ||
class ArgShouldBeVariable extends ValidationRule { | ||
|
||
/** | ||
* Returns structure suitable for GraphQL\Language\Visitor | ||
* | ||
* @see \GraphQL\Language\Visitor | ||
* | ||
* @return mixed[] | ||
*/ | ||
public function getVisitor( ValidationContext $context ) { | ||
|
||
return [ | ||
NodeKind::ARGUMENT => [ | ||
'enter' => function ( ArgumentNode $node ) use ( $context ) { | ||
// Arguments in operation are process here, ex. post( id: "1", idType: DATABASE_ID ) | ||
|
||
// If this argument should map to a variable | ||
// For a string or "idType" enum | ||
if ( in_array( $node->value->kind, [ 'StringValue', 'EnumValue' ], true ) ) { | ||
$context->reportError(new Error( | ||
self::shouldBeVariableMessage( $node->name->value ), | ||
$node | ||
)); | ||
} | ||
}, | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @param string $varName | ||
* @return string | ||
*/ | ||
public static function shouldBeVariableMessage( $varName ) { | ||
return sprintf( __( 'Argument "$%s" should be a variable.', 'wp-graphql-smart-cache' ), $varName ); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds the other rules to the query string validation.