Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-request

Package Overview
Dependencies
Maintainers
0
Versions
206
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-request

Minimal GraphQL client supporting Node and browsers for scripts or simple apps.

  • 7.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is graphql-request?

The graphql-request npm package is a minimal GraphQL client for Node.js and browsers, providing a simple and flexible way to execute GraphQL queries, mutations, and subscriptions. It is designed for making HTTP requests to a GraphQL server, and it's a lightweight alternative to more complex GraphQL clients like Apollo Client or Relay.

What are graphql-request's main functionalities?

Simple Query Execution

Execute a simple GraphQL query and log the result.

const { request } = require('graphql-request');
const query = `{ hello }`;
request('https://api.graph.cool/simple/v1/movies', query).then((data) => console.log(data));

Mutation Execution

Execute a GraphQL mutation to create a new resource and log the result.

const { request } = require('graphql-request');
const mutation = `mutation ($title: String!) { createMovie(title: $title) { id } }`;
const variables = { title: 'Inception' };
request('https://api.graph.cool/simple/v1/movies', mutation, variables).then((data) => console.log(data));

Error Handling

Handle errors that may occur during the execution of a GraphQL request.

const { request } = require('graphql-request');
const query = `{ hello }`;
request('https://api.graph.cool/simple/v1/movies', query).catch((error) => console.error(error.response.errors));

GraphQL Subscriptions

Set up a GraphQL subscription to listen for real-time updates.

const { SubscriptionClient } = require('graphql-request');
const ws = require('ws');
const subscriptionClient = new SubscriptionClient('wss://api.graph.cool/simple/v1/movies', { reconnect: true }, ws);
const query = `subscription { newMovie { id title } }`;
const observer = subscriptionClient.request({ query }).subscribe({
  next(data) { console.log(data); },
  error(err) { console.error(err); }
});

Other packages similar to graphql-request

Keywords

FAQs

Package last updated on 02 Nov 2024

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc