Skip to content

Parse OperationParams into strongly typed data structures - #1019

Draft
spawnia wants to merge 1 commit into
masterfrom
parse-operation-params
Draft

Parse OperationParams into strongly typed data structures#1019
spawnia wants to merge 1 commit into
masterfrom
parse-operation-params

Conversation

@spawnia

@spawnia spawnia commented Nov 25, 2021

Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors GraphQL server request/operation handling with the goal of parsing OperationParams into more strongly typed structures and adjusting persisted-query-related behavior, while updating the server test suite accordingly.

Changes:

  • Refactors GraphQL\Server\Helper::promiseToExecuteOperation() to perform parameter validation and persisted query resolution inline.
  • Introduces new DTO-style classes GraphQL\Server\ValidOperation and GraphQL\Server\PersistedOperation.
  • Updates server tests to reflect the new parsing/loader expectations.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
tests/Server/RequestValidationTest.php Switches validation calls to a new parseOperationParams API (currently missing in implementation).
tests/Server/QueryExecutionTest.php Updates one persisted query loader callback to use PersistedOperation.
src/Server/ValidOperation.php Adds a new DTO for “validated” operations.
src/Server/PersistedOperation.php Adds a new DTO for persisted operations.
src/Server/Helper.php Refactors execution-time validation, persisted query loading, and error handling flow.
Comments suppressed due to low confidence (1)

tests/Server/RequestValidationTest.php:67

  • Same issue as above: Helper::parseOperationParams() does not exist in the current changeset, so this assertion helper will fatal at runtime until the method is implemented or the test is updated to use the correct API.
    private function assertInputError($parsedRequest, $expectedMessage): void
    {
        $helper = new Helper();
        $errors = $helper->parseOperationParams($parsedRequest);
        if (isset($errors[0])) {

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/Server/Helper.php

return $promiseAdapter->createFulfilled(
new ExecutionResult(null, $locatedErrors)
if ($extensions !== null && (! is_array($extensions) || isset($variables[0]))) {
Comment thread src/Server/Helper.php
Comment on lines +243 to +247
if ($queryId !== null) {
if (! is_string($queryId)) {
$errors[] = new RequestError(
'GraphQL Request parameter "queryId" must be string, but got ' .
Utils::printSafeJson($params->queryId)
Comment thread src/Server/Helper.php
Comment on lines +289 to +293
if ($operationAST === null) {
$errors[] = new RequestError('Failed to determine operation type');
}

$operationType = $operationAST->operation;
Comment thread src/Server/Helper.php
Comment on lines +302 to 309
if (count($errors) > 0) {
return $promiseAdapter->createFulfilled(
new ExecutionResult(
null,
array_map([Error::class, 'createLocatedError'], $errors)
)
);
}
Comment thread src/Server/Helper.php
Comment on lines +208 to +210
return $promiseAdapter->createFulfilled(
new ExecutionResult(null, [Error::createLocatedError($batchedQueriesAreNotSupported)])
);
Comment on lines +407 to +408
->setPersistedQueryLoader(static function (PersistedOperation $persistedOperation): string {
if ($persistedOperation->queryId === 'some-id') {
Comment on lines 28 to 32
private static function assertValid($parsedRequest): void
{
$helper = new Helper();
$errors = $helper->validateOperationParams($parsedRequest);
$errors = $helper->parseOperationParams($parsedRequest);
self::assertEmpty($errors, isset($errors[0]) ? $errors[0]->getMessage() : '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants