A lightweight JavaScript package for making GraphQL queries to a specified endpoint URL.
npm install graphql-client
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));
Creates a new GraphQL client instance with the specified GraphQL endpoint URL.
-
url
(string): The URL of the GraphQL endpoint.
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.
This project is licensed under the MIT License - see the LICENSE file for details.