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

@graphql-tools/url-loader

Package Overview
Dependencies
Maintainers
3
Versions
1599
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/url-loader

A set of utils for faster development of GraphQL tools

  • 8.0.10-rc-20241030123030-4bc825bef28539fbe7ab043e0d55a17dd7a2ddae
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7M
increased by7.21%
Maintainers
3
Weekly downloads
 
Created

What is @graphql-tools/url-loader?

The @graphql-tools/url-loader package is designed for loading GraphQL schemas and operations over HTTP. It supports loading schemas through introspection, using GET or POST requests, and handling GraphQL operations such as queries, mutations, and subscriptions over HTTP or WebSockets. This package is part of the GraphQL Tools ecosystem, which provides a set of utilities for working with GraphQL in various environments.

What are @graphql-tools/url-loader's main functionalities?

Loading a GraphQL schema from a URL

This feature allows you to load a GraphQL schema from a remote endpoint. The `loadSchema` function uses the `UrlLoader` to fetch the schema using introspection from the provided URL.

const { loadSchema } = require('@graphql-tools/url-loader');

async function getSchema() {
  const schema = await loadSchema('http://your-graphql-endpoint.com/graphql', {
    loaders: [
      new UrlLoader()
    ]
  });
  return schema;
}

Executing a GraphQL operation using fetch

This demonstrates how to execute a GraphQL operation (query, mutation, or subscription) against a remote endpoint. The `UrlLoader` provides an `executor` function that can be used to send operations to the GraphQL server.

const { loadSchema, UrlLoader } = require('@graphql-tools/url-loader');

async function executeOperation(operation) {
  const loader = new UrlLoader();
  const executor = loader.getExecutor('http://your-graphql-endpoint.com/graphql');
  const result = await executor({
    document: operation
  });
  return result;
}

Subscribing to GraphQL subscriptions over WebSocket

This feature enables subscribing to GraphQL subscriptions using WebSockets. It leverages the `subscriptions-transport-ws` library to create a WebSocket client and then uses `createClient` from `@graphql-tools/url-loader` to handle subscriptions.

const { SubscriptionClient } = require('subscriptions-transport-ws');
const { createClient } = require('@graphql-tools/url-loader');

const wsClient = new SubscriptionClient('ws://your-graphql-endpoint.com/graphql', {
  reconnect: true
});

const client = createClient({
  url: 'http://your-graphql-endpoint.com/graphql',
  webSocketImpl: wsClient
});

const subscription = client.request({
  query: 'subscription { newData }'
}).subscribe({
  next(data) {
    console.log(data);
  }
});

Other packages similar to @graphql-tools/url-loader

FAQs

Package last updated on 30 Oct 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