Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
@graphql-tools/executor
Advanced tools
Fork of GraphQL.js' execute function
@graphql-tools/executor is a package that provides tools for executing GraphQL operations. It is part of the larger GraphQL Tools ecosystem, which offers a variety of utilities for building and managing GraphQL schemas and operations.
Basic Execution
This feature allows you to execute a basic GraphQL query against a schema. The code sample demonstrates creating a simple schema with a single query and executing it.
const { execute } = require('@graphql-tools/executor');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const typeDefs = `
type Query {
hello: String
}
`;
const resolvers = {
Query: {
hello: () => 'Hello world!',
},
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
const query = `{
hello
}`;
execute({ schema, document: query }).then(result => {
console.log(result);
});
Custom Execution Context
This feature allows you to pass a custom context to the execution. The code sample demonstrates how to use a context value in a resolver.
const { execute } = require('@graphql-tools/executor');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const typeDefs = `
type Query {
hello(name: String): String
}
`;
const resolvers = {
Query: {
hello: (_, { name }) => `Hello ${name || 'world'}!`,
},
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
const query = `{
hello(name: "Alice")
}`;
const context = { user: 'Alice' };
execute({ schema, document: query, contextValue: context }).then(result => {
console.log(result);
});
Subscription Execution
This feature allows you to execute GraphQL subscriptions. The code sample demonstrates setting up a subscription and publishing an event.
const { subscribe } = require('@graphql-tools/executor');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const { PubSub } = require('graphql-subscriptions');
const pubsub = new PubSub();
const typeDefs = `
type Query {
_empty: String
}
type Subscription {
messageSent: String
}
`;
const resolvers = {
Subscription: {
messageSent: {
subscribe: () => pubsub.asyncIterator(['MESSAGE_SENT']),
},
},
};
const schema = makeExecutableSchema({ typeDefs, resolvers });
const subscriptionQuery = `
subscription {
messageSent
}
`;
(async () => {
const iterator = await subscribe({ schema, document: subscriptionQuery });
for await (const result of iterator) {
console.log(result);
}
})();
// Simulate sending a message
setTimeout(() => {
pubsub.publish('MESSAGE_SENT', { messageSent: 'Hello world!' });
}, 1000);
The 'graphql' package is the reference implementation of GraphQL for JavaScript. It provides the core functionality for parsing, validating, and executing GraphQL queries. While it offers similar execution capabilities, it does not include the higher-level utilities provided by @graphql-tools/executor.
Apollo Server is a community-maintained open-source GraphQL server that works with any GraphQL schema. It provides a more comprehensive solution for building GraphQL APIs, including schema stitching, data sources, and more. It includes execution capabilities but is more feature-rich compared to @graphql-tools/executor.
GraphQL Yoga is a fully-featured GraphQL server with focus on easy setup, performance, and great developer experience. It provides a higher-level abstraction over the core 'graphql' package, including execution, but also offers additional features like subscriptions and file uploads.
@graphql-tools/executor
Fork of GraphQL.js' execute function
FAQs
Fork of GraphQL.js' execute function
The npm package @graphql-tools/executor receives a total of 2,727,005 weekly downloads. As such, @graphql-tools/executor popularity was classified as popular.
We found that @graphql-tools/executor demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.