Skip to content

GraphQL CORS Headers #28713

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

Conversation

michalderlatka
Copy link
Contributor

Description (*)

As a web developer, I want Magento to support the CORS standard so that I can develop my applications according to defined best practices.

Related Pull Requests

Fixed Issues (if relevant)

  1. Fixes GraphQL : CORS requests will fail without OPTIONS reponse #28561

Manual testing scenarios (*)

  1. go to admin > stores > configuration > services > graphql
  2. enable CORS headers
  3. Fill fields with data
  4. save and clean cache
  5. run graphQL query and confirm headers are added

Questions or comments

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds are green)

@m2-assistant
Copy link

m2-assistant bot commented Jun 12, 2020

Hi @michalderlatka. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento give me test instance - deploy test instance based on PR changes
  • @magento give me 2.4-develop instance - deploy vanilla Magento instance

❗ Automated tests can be triggered manually with an appropriate comment:

  • @magento run all tests - run or re-run all required tests against the PR changes
  • @magento run <test-build(s)> - run or re-run specific test build(s)
    For example: @magento run Unit Tests

<test-build(s)> is a comma-separated list of build names. Allowed build names are:

  1. Database Compare
  2. Functional Tests CE
  3. Functional Tests EE,
  4. Functional Tests B2B
  5. Integration Tests
  6. Magento Health Index
  7. Sample Data Tests CE
  8. Sample Data Tests EE
  9. Sample Data Tests B2B
  10. Static Tests
  11. Unit Tests
  12. WebAPI Tests

You can find more information about the builds here

ℹ️ Please run only needed test builds instead of all when developing. Please run all test builds before sending your PR for review.

For more details, please, review the Magento Contributor Guide documentation.

@lenaorobei
Copy link
Contributor

@magento run all tests

@michalderlatka michalderlatka force-pushed the 28561_graphql_cors_requests branch from 3db87dc to 50635d9 Compare June 18, 2020 12:22
@michalderlatka michalderlatka requested a review from cpartica June 22, 2020 12:49
Copy link
Contributor

@cpartica cpartica left a comment

Choose a reason for hiding this comment

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

just a few "static failures" that need addressing,
you'll see them in the builds that I just just ran https://github.com/magento/magento2/pull/28713/checks?check_run_id=797040005

@cpartica
Copy link
Contributor

@magento run all tests

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@michalderlatka
Copy link
Contributor Author

@magento run all tests

@michalderlatka michalderlatka requested a review from cpartica June 23, 2020 12:01
cpartica
cpartica previously approved these changes Jun 23, 2020
@ghost ghost removed the Progress: needs update label Jun 23, 2020
*
* @return bool
*/
public function isEnabled() : bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant space after ) and before :.

*/
class Configuration implements ConfigurationInterface
{
const XML_PATH_CORS_HEADERS_ENABLED = 'graphql/cors/enabled';
Copy link
Contributor

Choose a reason for hiding this comment

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

Constants should have visibility scope.

*
* @return string
*/
public function getName()
Copy link
Contributor

Choose a reason for hiding this comment

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

The method return type is missed.

@@ -98,4 +98,31 @@
<argument name="queryComplexity" xsi:type="number">300</argument>
</arguments>
</type>

<preference for="Magento\GraphQl\Model\Cors\ConfigurationInterface" type="Magento\GraphQl\Model\Cors\Configuration" />
<type name="\Magento\GraphQl\Controller\HttpResponse\Cors\CorsMaxAgeHeaderProvider">
Copy link
Contributor

Choose a reason for hiding this comment

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

Redundant \ in FQCN.


protected function tearDown(): void
{
parent::tearDown(); // TODO: Change the autogenerated stub
Copy link
Contributor

Choose a reason for hiding this comment

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

@TODO annotations should be removed from code.

self::assertArrayNotHasKey('Access-Control-Allow-Origin', $headers);
}

private function getHeadersFromIntrospectionQuery()
Copy link
Contributor

Choose a reason for hiding this comment

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

The method return type is missed.

Copy link
Contributor

Choose a reason for hiding this comment

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

we don't usually do it on tests, but since we upgraded phpunit we might have to

Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't matter if a method is a test class method or a regular code. All code should follow the same semantic, the only exception is doc blocks, they can be omitted for test methods.

@ghost ghost assigned YevSent Jun 24, 2020
self::assertArrayNotHasKey('Access-Control-Allow-Origin', $headers);
}

private function getHeadersFromIntrospectionQuery()
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't usually do it on tests, but since we upgraded phpunit we might have to

@cpartica cpartica added the PAP Partners acceleration program label Jun 25, 2020
@michalderlatka
Copy link
Contributor Author

@magento run all tests

@m2-assistant
Copy link

m2-assistant bot commented Jun 27, 2020

Hi @michalderlatka, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@michalderlatka michalderlatka deleted the 28561_graphql_cors_requests branch June 27, 2020 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

GraphQL : CORS requests will fail without OPTIONS reponse
6 participants