Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
@graphql-tools/url-loader
Advanced tools
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.
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);
}
});
Similar to @graphql-tools/url-loader, `apollo-link-http` provides capabilities to send GraphQL operations over HTTP. It is part of the Apollo ecosystem and is designed to work seamlessly with Apollo Client. However, it does not natively support loading GraphQL schemas or subscriptions over WebSockets.
A minimal GraphQL client for sending queries and mutations, `graphql-request` is simpler and more lightweight compared to @graphql-tools/url-loader. It does not support loading schemas or handling subscriptions, focusing instead on providing a straightforward way to execute GraphQL operations.
This package focuses specifically on handling GraphQL subscriptions over WebSockets. While @graphql-tools/url-loader supports subscriptions as part of its broader functionality, `subscriptions-transport-ws` is dedicated solely to this aspect, offering more specialized features for subscription management.
FAQs
A set of utils for faster development of GraphQL tools
The npm package @graphql-tools/url-loader receives a total of 2,705,330 weekly downloads. As such, @graphql-tools/url-loader popularity was classified as popular.
We found that @graphql-tools/url-loader demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
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.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.