Apollo-compatible automatic persisted queries, to improve GraphQL network performance.

Overview

Automatic Persisted Queries for Magento 2

Apollo-compatible automatic persisted queries, to improve GraphQL network performance.

APQ

Please check Apollo documentation for more information.

License

Copyright (c) 2021 Daniel Sloof

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Issues
  • apollo persistent link is not working as expected

    apollo persistent link is not working as expected

    I am currently trialling this with PWA studio with using @apollo/client/link/persisted-queries https://www.apollographql.com/docs/react/api/link/persisted-queries/

    Contrary to the documentation here image

    in my trials the client on the missed hash response does resend the query but never includes the hash. Not sure if this is an outdated graphic or something undocumented in the apollo client.

    Currently simply having the server always create the hash seems to work better

        public function afterDispatch(
            GraphQl $subject,
            ResponseInterface $result,
            RequestInterface $request
        ): ResponseInterface {
            $data = $this->getDataFromRequest($request);
    
            if (!isset($data['query'])) {
                return $result;
            }
    
            $cacheKey = $this->getCacheKeyFromQueryHash(hash('sha256', $data['query']));
            if ($this->cache->load($cacheKey) === false) {
                $this->cache->save($data['query'], $cacheKey, [Apq::CACHE_TAG]);
            }
    
            return $result;
        }
    

    Keen to hear if you are seeing something different.

    opened by fooman 8
  • Add testcase for multistore

    Add testcase for multistore

    Magento's GraphQl unfortunately uses a custom header to differentiate store views. For the moment just adding the testcase here to document as I am not sure at what stage this should be best solved (frontend client, apollo automatic persisted queries or here). There is also a related dimension to the currency or Authorisation header (as for example logged in users might get a different price based on customer group).

    I have previously trialled converting the custom header to /graphql?store='store_view_code&query={...}' but I believe that is still not very aligned with how graphql is most commonly used and might still require a custom hash function in the frontend https://github.com/apollographql/apollo-client/blob/main/src/link/persisted-queries/index.ts#L112

    opened by fooman 2
  • Handle queries without hash

    Handle queries without hash

    fixes #6

    opened by fooman 2
  • add integration tests

    add integration tests

    Use https://github.com/extdn/github-actions-m2 to add integration tests.

    Ensure:

    • Persistent query not found with POST: status 500.
    • Persistent query not found with GET: status 400.
    • Query is cached.
    • SHA256 does not match: status 405 and body provided sha does not match query.
    opened by danslo 1
  • allow faster cache hit

    allow faster cache hit

    Typical request chain when cache is not warm:

    1. Get query with persistent query hash only [PERSISTED_QUERY_NOT_FOUND]
    2. POST query with persistent query hash and query.
    3. GET query with persistent query hash only.
    4. GET query with persistent query hash only.
    5. GET query with persistent query hash only.
    6. etc...

    Currently we only get a X-Magento-Cache-Debug: HIT on the 4th request forward. It should be possible to do this on the 3rd request by tinkering with FPC in 2nd request.

    Cover it with tests.

    opened by danslo 0
Releases(1.1.0)
Create Your Own Broadcast Network With AVideo Platform Open-Source. OAVP OVP

Audio Video Platform AVideo is a term that means absolutely nothing, or anything video. Since it doesn't mean anything the brand simply is identifiabl

World Wide Broadcast Network 1.4k Jun 15, 2021
EasyQuickImport — Import transactions, invoices and bills into QuickBooks Desktop from Excel or CSV

EasyQuickImport is a tool that helps you import invoices, bills, transactions, customers and vendors into QuickBooks Desktop in multiple currencies in bulk.

Dmitrii Poddubnyi 5 Jun 22, 2021
Source code of Strm.pl, brand-new social service.

Strimoid Source code of Strm.pl, brand-new social service.

Strimoid 56 Apr 24, 2021
BraincraftedBootstrapBundle integrates Bootstrap into Symfony2 by providing templates, Twig extensions, services and commands.

BraincraftedBootstrapBundle BraincraftedBootstrapBundle helps you integrate Bootstrap in your Symfony2 project. BootstrapBundle also supports the offi

Braincrafted 411 Jun 5, 2021
A high performance full-featured project management system

Interested in managed hosting? Take a brief survey to help us know what to build! Phproject A high-performance project management system in PHP Instal

Alan Hardman 327 Jun 8, 2021
A platform to create documentation/wiki content built with PHP & Laravel

BookStack A platform for storing and organising information and documentation. Details for BookStack can be found on the official website at https://w

BookStackApp 6.7k Jun 14, 2021
📛 An open source status page system for everyone.

Cachet is a beautiful and powerful open source status page system. Overview List your service components Report incidents Customise the look of your s

Cachet 12.1k Jun 21, 2021
phpSysInfo: a customizable PHP script that displays information about your system nicely

phpSysInfo Copyright (c), 1999-2008, Uriah Welcome (sf.net/users/precision) Copyright (c), 1999-2009, Michael Cramer (sf.net/users/bigmichi1) Copyrigh

phpSysInfo 1.2k Jun 13, 2021