billymoorgraphql

1.1.5 • Public • Published

GraphQL Client

A lightweight JavaScript package for making GraphQL queries to a specified endpoint URL.

Installation

npm install graphql-client

Usage

const GraphQLClient = require('graphql-client');

const client = new GraphQLClient('https://example.com/graphql');

const query = `
  query {
    posts {
      title
      body
    }
  }
`;

client.query(query)
  .then(data => console.log('Data:', data))
  .catch(error => console.error('Error:', error));

API

new GraphQLClient(url)

Creates a new GraphQL client instance with the specified GraphQL endpoint URL.

  • url (string): The URL of the GraphQL endpoint.

query(query, variables)

Executes a GraphQL query with optional variables.

  • query (string): The GraphQL query string.
  • variables (object, optional): The variables used in the query.

Returns a Promise that resolves with the query result.

License

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

Readme

Keywords

none

Package Sidebar

Install

npm i billymoorgraphql

Weekly Downloads

0

Version

1.1.5

License

MIT

Unpacked Size

2.3 kB

Total Files

4

Last publish

Collaborators

  • billymoor