Skip to content
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

Fix performance when parsing GraphQL schema into AST which causes downtime on cache stampede #31879

Commits on Jan 26, 2021

  1. Add graphql stitching test

    convenient committed Jan 26, 2021
    Configuration menu
    Copy the full SHA
    51aab9d View commit details
    Browse the repository at this point in the history

Commits on Jan 28, 2021

  1. Configuration menu
    Copy the full SHA
    0672892 View commit details
    Browse the repository at this point in the history

Commits on May 10, 2021

  1. Configuration menu
    Copy the full SHA
    6772386 View commit details
    Browse the repository at this point in the history

Commits on May 13, 2021

  1. Fix Syntax Error: Expected Name found :

    There was a bug with the enum placeholder ordering
    
    Input like the following
    ```
                interface SomeInterface  {
                    product_type: String @doc(description: "The type of product, such as simple, configurable, etc.")
                }
                enum SomeEnum {
                }
    ```
    
    would have placeholder logic ran against it and end up like
    ```
                interface SomeInterface  {
                    product_type: String @doc(description: "The type of product, such as simple, configurable, etc.")
                }
                enum SomeEnum {
    placeholder_graphql_field: String
    }
    ```
    
    This caused an error, something in the AST was trying to make it resolve against the word "Type" in the @doc description
    
    By fixing the enum so that it does not have `: String` in it the AST is generated successfully, we do this by replacing those empty enums first so that they cannot get caught by the empty type check
    convenient committed May 13, 2021
    Configuration menu
    Copy the full SHA
    15bad09 View commit details
    Browse the repository at this point in the history
  2. WIP - Add proof of bug for union types

    The newly supported union is the cause of this issue in the parseTypes function.
    
    The regex is finding the type of union CompanyStructureEntity but its also grabbing the item below it and including it as part of its schema content, which means CompanyStructureEntity contains the schema for itself as well as CompanyStructureItem , this means I never have a $knownTypes['CompanyStructureItem']  to work with which means it is a missing dependency.
    
    ```
    <?php
    use Magento\Framework\App\Bootstrap;
    require __DIR__ . '/app/bootstrap.php';
    ​
    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $obj = $bootstrap->getObjectManager();
    /** @var Magento\Framework\GraphQlSchemaStitching\GraphQlReader $graphqlReader */
    $graphqlReader = $obj->get(Magento\Framework\GraphQlSchemaStitching\GraphQlReader::class);
    $reflector = new ReflectionObject($graphqlReader);
    $method = $reflector->getMethod('parseTypes');
    $method->setAccessible(true);
    ​
    $broken =
    'type IsCompanyEmailAvailableOutput @doc(description: "Contains the response of a company email validation query") {
        is_email_available: Boolean! @doc(description: "A value of `true` indicates the email address can be used to create a company")
    }
    ​
    union CompanyStructureEntity @typeResolver(class: "Magento\\CompanyGraphQl\\Model\\Resolver\\StructureEntityTypeResolver") = CompanyTeam | Customer
    ​
    type CompanyStructureItem @doc(description: "Defines an individual node in the company structure") {
        id: ID! @doc(description: "The unique ID for a `CompanyStructureItem` object")
        parent_id: ID @doc(description: "The ID of the parent item in the company hierarchy")
        entity: CompanyStructureEntity @doc(description: "A union of `CompanyTeam` and `Customer` objects")
    }
    ​
    type CompanyStructure @doc(description: "Contains an array of the individual nodes that comprise the company structure") {
        items: [CompanyStructureItem] @doc(description: "An array of elements in a company structure")
    }';
    ​
    $result = $method->invoke($graphqlReader, $broken);
    ​
    echo "Got the following types" . PHP_EOL;
    echo implode(PHP_EOL, array_keys($result)) . PHP_EOL;
    ​
    echo "The values for the union actually contains CompanyStructureItem which is why the initial approach works any mine does not" . PHP_EOL;
    echo $result['CompanyStructureEntity'] . PHP_EOL;
    ```
    convenient committed May 13, 2021
    Configuration menu
    Copy the full SHA
    cfcbcd8 View commit details
    Browse the repository at this point in the history
  3. Fix test class name

    convenient committed May 13, 2021
    Configuration menu
    Copy the full SHA
    075a261 View commit details
    Browse the repository at this point in the history

Commits on Aug 6, 2021

  1. Update GraphQlReader.php

    Based on feedback from magento#31879 (comment) @Bartlomiejsz
    
    > regarding first issue - with empty enum. It looks like the fix is to replace first matching group in both $typeDefinitionPattern variables:
    >
    > ([^\{]*)
    > with:
    > 
    > ([^\{\}]*)
    > Then this regex will check if there is neither beginning or ending bracket in this place
    convenient authored Aug 6, 2021
    Configuration menu
    Copy the full SHA
    7223e89 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    53c5cf8 View commit details
    Browse the repository at this point in the history

Commits on Aug 9, 2021

  1. Revert "Update GraphQlReader.php"

    This reverts commit 53c5cf8.
    convenient committed Aug 9, 2021
    Configuration menu
    Copy the full SHA
    91a5319 View commit details
    Browse the repository at this point in the history
  2. Revert "Update GraphQlReader.php"

    This reverts commit 7223e89.
    convenient committed Aug 9, 2021
    Configuration menu
    Copy the full SHA
    2624d93 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    416a593 View commit details
    Browse the repository at this point in the history

Commits on Aug 16, 2021

  1. Configuration menu
    Copy the full SHA
    afa8b04 View commit details
    Browse the repository at this point in the history

Commits on Oct 1, 2021

  1. Update GraphQlReader.php

    Based on feedback magento#31879 (comment) from @Bartlomiejsz
    
    > regarding first issue - with empty enum. It looks like the fix is to replace first matching group in both $typeDefinitionPattern variables:
    >
    > ([^\{]*)
    > with:
    >
    > ([^\{\}]*)
    > Then this regex will check if there is neither beginning or ending bracket in this place
    convenient committed Oct 1, 2021
    Configuration menu
    Copy the full SHA
    8e8d364 View commit details
    Browse the repository at this point in the history
  2. Fix code style

    convenient committed Oct 1, 2021
    Configuration menu
    Copy the full SHA
    459cbbe View commit details
    Browse the repository at this point in the history

Commits on Oct 8, 2021

  1. Merge remote-tracking branch 'upstream/2.4-develop' into improve-grap…

    …hql-stitching-perf
    
     Conflicts:
    	lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php
    convenient committed Oct 8, 2021
    Configuration menu
    Copy the full SHA
    603963e View commit details
    Browse the repository at this point in the history

Commits on Oct 9, 2021

  1. Update GraphQlReader, generalise union handling

    This workaround handles a bug where parseTypes also contains the data from below it
    
    ```
    union X = Y | Z
    
    type foo {}
    ```
    
    Would return
    ```php
    [
        'x' => 'union X = Y | Z
    
        type foo {}'
    ]
    ```
    
    instead of
    ```php
    [
        'x' => 'union X = Y | Z',
        'foo' => 'type foo {}'
    ]
    ```
    
    This workaround deals only with union types, so doesnt materially affect anything in most cases.
    convenient committed Oct 9, 2021
    Configuration menu
    Copy the full SHA
    c36fb66 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    00ff074 View commit details
    Browse the repository at this point in the history