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.

Comments
  • 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
  • Category doesn't have id set if this module is used

    Category doesn't have id set if this module is used

    Hi. I think I found a quite huge bug which I cannot really explain to myself how it's happening. If this module is enabled and I request a category via the categories query, the category doesn't have an id if requested as persisted query. If I request the category normally, without the usage of persisted queries, everything works fine.

    This leads to some problems, for example in when requesting the category canonical field. In the resolver for the field the function getUrl is executed.

    The function getUrl tries to retrieve a rewrite as seen here. It cannot find an entry as at this point the id of the category is not set which will lead to the function getCategoryIdUrl (directly below) which then returns catalog/category/view/ without the id as it's not set of course.

    In the variable $value in resolvers the id is set ($value['id']), but not in $value['model'] where the corresponding model resides.

    I have no idea how this problem occurs, but it definitly only occurs when using persisted queries via this module. And only for categories, for products everything is working as it should.

    @danslo Do you have any idea why this happens?

    opened by oneserv-heuser 1
  • 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)
Owner
Daniel Sloof
Daniel Sloof
Automatic SASS-to-CSS compiling for Laravel 4 (and any other framework too), config-free, in pure PHP, works with latest SASS 3.2 .scss syntax, imports and mixins

laravel-sass Automatic Sass-to-CSS compiling for Laravel 4 (and any other framework by the way) while being in development. Every time you run your ap

Chris 71 Nov 29, 2022
MyAAC is a free and open-source Automatic Account Creator (AAC) written in PHP

MyAAC is a free and open-source Automatic Account Creator (AAC) written in PHP. It supports only MySQL databases.

Lucas Giovanni 6 Aug 26, 2022
Anemone - an application that centralizes users' documentation queries

Anemone C. Sun, F. Imadegbelo, F. Johnston, T. Rowe, W. Zhai Anemone is an application that centralizes users' documentation queries. A user will be a

Temple University, CIS department 5 Apr 22, 2022
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.7k Jan 8, 2023
Centreon is a network, system and application monitoring tool. Centreon is the only AIOps Platform Providing Holistic Visibility to Complex IT Workflows from Cloud to Edge.

Centreon - IT and Application monitoring software Introduction Centreon is one of the most flexible and powerful monitoring softwares on the market;

Centreon 14 Dec 16, 2022
LibreNMS is an auto-discovering PHP/MySQL/SNMP based network monitoring system

LibreNMS is an auto-discovering PHP/MySQL/SNMP based network monitoring which includes support for a wide range of network hardware and operating systems including Cisco, Linux, FreeBSD, Juniper, Brocade, Foundry, HP and many more.

LibreNMS Project 3k Dec 30, 2022
the network of free stuff

home Free Net get free stuff give away free stuff ask for help help people out tell a story about free net hear a story about free net replicate and s

Trash Robot 1 Oct 31, 2021
Project Website Social Network Laravel, Vue3

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Old Wolf 1 Nov 4, 2021
Open Source Social Network (OSSN) is a social networking software written in PHP.

Open Source Social Network (OSSN) is a social networking software written in PHP. It allows you to make a social networking website and helps your members build social relationships, with people who share similar professional or personal interests. It is available in 17 international languages.

Open Source Social Network 923 Jan 6, 2023
Social media network with laravel

Social Network Tech Includes Front End: Post CSS Tailwind CSS v3 Back End: Laravel v8 PHP v8 MySQL v8 Asset Bundling: Laravel Mix Features How to use

Noval 3 Apr 20, 2022
Online chatting application through a logical decentralized blockchain network that stores chat information and hashing keys implemented using AJAX, JQuery, PHP, SQL, CSS, and HTML

Online chatting application through a logical decentralized blockchain network that stores chat information and hashing keys implemented using AJAX, JQuery, PHP, SQL, CSS, and HTML. The blockchain stores a previous hash value, current hash value, time, chat data, and a special key(nonce) used for encryption in each block (node).

Dave Sharma 1 Jan 4, 2022
Interface Network is an application about social media

Interface Network is an application about social media

Noval 3 Apr 20, 2022
Social Network - Social Media App

Social Network Social Network - Social Media App. Demo Features Auth System (Login, Register, Forgot Password, Password Reset & Email Verification) Us

Noval 2 Jan 18, 2022
Cruuzr is a social network with a target demographic of motor vehicle enthusiasts.

Cruuzr Social Network Cruuzr is a social network with a target demographic of motor enthusiasts. The website was designed using bootstrap to allow for

Orson Hannath 1 Apr 5, 2022
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 357 Dec 27, 2022
Web Frameworks Performance Comparison

Which Web Framework is Faster? Basic out of the box Web frameworks performance comparison There are numerous of backend web frameworks for different p

Alex Chaplinsky 12 Nov 10, 2022
Enable query locking for WPGraphQL by implementing persisted GraphQL queries.

?? WP GraphQL Lock This plugin enables query locking for WPGraphQL by implementing persisted GraphQL queries. Persisted GraphQL queries allow a GraphQ

Valu Digital 21 Oct 9, 2022
[ALPHA] Implementation of persisted queries for WPGraphQL

WPGraphQL Persisted Queries Persisted GraphQL queries allow a GraphQL client to optimistically send a hash of the query instead of the full query; if

Quartz 18 Jun 20, 2022
An Instagram clone built with TailwindCSS, React, Apollo Client and Laravel Lighthouse.

This is an Instagram clone built with TailwindCSS, React, Apollo Client and Laravel Lighthouse. This is a great project to learn and improve your Tailwind and React skills also if you are insterested in backend, the GraphQL API is created using Laravel Lighthouse, this is a great project to add to your portfolio if you are just starting as a web developer or full stack developer.

Carlos Mafla 13 Dec 12, 2022
IMAGON is an image optimization and compression API Free, that helps improve your website performance.

IMAGON API Demo Image Optimization and Compression API by IMAGON IMAGON is an image optimization and compression API Free, that helps improve your web

Nashwan Abdullah 3 Jan 15, 2022