mage2tv/module-apollo-boost-amd

The popular apollo-boost graphql library transpiled to AMD, wrapped in a Magento 2 module.

Installs: 14 618

Dependents: 0

Suggesters: 0

Security: 0

Stars: 8

Watchers: 4

Forks: 2

Open Issues: 0

Type:magento2-module

0.3.1.1 2019-05-28 07:36 UTC

This package is auto-updated.

Last update: 2024-04-28 19:14:14 UTC


README

The popular apollo-boost library transpiled to AMD and wrapped in a Magento 2 module.

Usage:

  • Install mage2tv/module-apollo-boost-amd

  • In your JavaScript AMD modules, require 'apollo-boost'

  • Use the "exported" ApolloClient and gql function:

const client = new ApolloAmd.ApolloClient();
const query = ApolloAmd.gql(my_graphql_query);

// or: 

const {ApolloClient, gql} = ApolloAmd;

Example:

define(['uiComponent', 'apollo-boost'], function (Component, ApolloAmd) {
    'use strict';

    const {ApolloClient, gql} = ApolloAmd;

    const client = new ApolloClient({url: '/graphql'});
    const query = gql(`
                query exampleProducts($count: Int = 1) {
                  products(filter: {} pageSize: $count sort: { name: DESC }) {
                    total_count
                    items {
                      id
                      type_id
                      name
                      sku
                    }
                  }
                }
    `);


    return Component.extend({
        defaults: {
            tracks: {
                result: true
            }
        },
        initialize: function () {
            client.query({
                query: query,
                variables: {
                    count: 3
                }
            })
            .then(data => {
                this.result = data;
            })
            .catch(console.error);
            return this._super();
        }
    });
});