Socket
Book a DemoInstallSign in
Socket

@shopify/graphql-js-client

Package Overview
Dependencies
Maintainers
0
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/graphql-js-client

Feature light client library for fetching resources via GraphQL

latest
Source
npmnpm
Version
0.4.1
Version published
Maintainers
0
Created
Source

graphql-js-client

Feature light client library for fetching resources via GraphQL

Table Of Contents

  • Installation
  • Examples
  • Contributing
  • License

Installation

$ yarn install graphql-js-client

Examples

GraphQLClient requires a "type bundle" which is a set of ES6 modules generated by graphql-js-schema that represent your GraphQL schema.

Creating and sending a query

import GraphQLClient from 'graphql-js-client';

// This is the generated type bundle from graphql-js-schema
import types from './types.js';

const client = new GraphQLClient(types, {
  url: 'https://graphql.myshopify.com/api/graphql',
  fetcherOptions: {
    headers: `Authorization: Basic ${btoa('some-storefront-access-token')}`
  }
});

const products = [];

client.send(client.query((root) => {
  root.add('shop', (shop) => {
    shop.add('name');
    shop.addConnection('products', {args: {first: 10}}, (product) => {
      product.add('title');
    });
  });
}).then(({model, data}) => {
  console.log(model); // The serialized model with rich features
  console.log(data); // The raw data returned from the endpoint

  products.push(...model.products);

  if (model.products.hasNextPage) {
    return client.fetchNextPage(model.products);
  };

// `fetchNextPage` resolves with the model you wanted the next page of
}).then(({model, data}) => {
  products.push(...model); // Page two of products
});

Contributing

Setting up:

$ git clone git@github.com:Shopify/graphql-js-client.git
$ cd graphql-js-client
$ yarn install

Running the tests in a browser

$ yarn start

Then visit http://localhost:4200

Running the tests in node

$ yarn test

License

MIT, see LICENSE.md for details.

Keywords

graphql,api,client

FAQs

Package last updated on 28 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.