2.0.0 • Published 9 months ago

shopify-api-graphql-client v2.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Shopify Api GraphQL Client

A lightweight and easy-to-use Node.js client for interacting with Shopify’s GraphQL API. This client allows developers to send GraphQL queries and mutations to Shopify and includes utility functions for OAuth token generation.

Installation

  npm install shopify-api-graphql-client

or

  yarn add shopify-api-graphql-client

API

A class for making requests to Shopify’s GraphQL API.

Constructor

new ShopifyGraphQLClient(shopName: string, accessToken: string, apiVersion?: string);
ParameterTypeDescription
shopNamestringRequired. The Shopify store domain in the format abc.myshopify.com
accessTokenstringRequired. The access token obtained from Shopify OAuth.
apiVersionstringoptional. The API version to use. Defaults to '2024-10'

Usage

import { ShopifyGraphQLClient } from 'shopify-api-graphql-client';

const client = new ShopifyGraphQLClient(
  'abc.myshopify.com',
  'your-access-token',
);
const query = `
    {
      shop {
        name
      }
    }
  `;

try {
  const data = await client.graphql(query);
  console.log('Shop data:', data);
} catch (error) {
  console.error('Error fetching shop data:', error.message);
}

Utility Functions

If you want to generate the app installation url for a shop

import { generateShopifyAppInstallURL } from 'shopify-api-graphql-client';

const installUrl = generateShopifyAppInstallURL(
  'abc.myshopify.com', // Shop domain in the format abc.myshopify.com
  process.env.CLIENT_ID!,
  process.env.SCOPES!,
  process.env.SHOPIFY_REDIRECT_URL!
);
console.log('Install URL:', installUrl);

If you want to get the access token for a shop using the code which is return after apps installation

import { getShopifyAccessToken } from 'shopify-api-graphql-client';


  try {
    const accessToken = await getShopifyAccessToken(
      code,
      shop,
      process.env.CLIENT_ID!,
      process.env.CLIENT_SECRET!
    );
    console.log('Access Token:', accessToken);
  } catch (error) {
    console.error('Error fetching access token:', error.message);
  }

Contributing

Contributions are always welcome! Please fork this repository and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

2.0.0

9 months ago

1.0.2

9 months ago

1.0.1

9 months ago