Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@graphql-tools/delegate
Advanced tools
A set of utils for faster development of GraphQL tools
@graphql-tools/delegate is a package that provides utilities for schema delegation in GraphQL. It allows you to delegate execution of a query to a different schema, enabling schema stitching, remote schema execution, and more.
Schema Delegation
This feature allows you to delegate a query to another schema. In this example, a simple schema is created and a query is delegated to it, returning 'Hello world!'.
const { delegateToSchema } = require('@graphql-tools/delegate');
const { makeExecutableSchema } = require('@graphql-tools/schema');
const schema = makeExecutableSchema({
typeDefs: `
type Query {
hello: String
}
`,
resolvers: {
Query: {
hello: () => 'Hello world!'
}
}
});
const result = await delegateToSchema({
schema,
operation: 'query',
fieldName: 'hello',
context: {},
info: {}
});
console.log(result); // Outputs: Hello world!
Remote Schema Execution
This feature allows you to execute queries against a remote schema. In this example, a remote schema is made executable and a query is delegated to it.
const { makeRemoteExecutableSchema } = require('@graphql-tools/wrap');
const { HttpLink } = require('apollo-link-http');
const fetch = require('node-fetch');
const link = new HttpLink({ uri: 'http://remote-graphql-server.com/graphql', fetch });
const schema = makeRemoteExecutableSchema({ link });
const result = await delegateToSchema({
schema,
operation: 'query',
fieldName: 'remoteField',
context: {},
info: {}
});
console.log(result);
Schema Stitching
This feature allows you to stitch multiple schemas together into a single schema. In this example, two schemas are stitched together and queries are delegated to each of them.
const { stitchSchemas } = require('@graphql-tools/stitch');
const schemaA = makeExecutableSchema({
typeDefs: `
type Query {
fieldA: String
}
`,
resolvers: {
Query: {
fieldA: () => 'Field A'
}
}
});
const schemaB = makeExecutableSchema({
typeDefs: `
type Query {
fieldB: String
}
`,
resolvers: {
Query: {
fieldB: () => 'Field B'
}
}
});
const stitchedSchema = stitchSchemas({
subschemas: [
{ schema: schemaA },
{ schema: schemaB }
]
});
const resultA = await delegateToSchema({
schema: stitchedSchema,
operation: 'query',
fieldName: 'fieldA',
context: {},
info: {}
});
const resultB = await delegateToSchema({
schema: stitchedSchema,
operation: 'query',
fieldName: 'fieldB',
context: {},
info: {}
});
console.log(resultA); // Outputs: Field A
console.log(resultB); // Outputs: Field B
Apollo Server is a community-maintained open-source GraphQL server that works with any GraphQL schema. It provides a straightforward setup for creating a GraphQL server and supports schema stitching and remote schema execution, similar to @graphql-tools/delegate.
GraphQL Yoga is a fully-featured GraphQL server with focus on easy setup, performance, and great developer experience. It supports schema stitching and remote schema execution, making it comparable to @graphql-tools/delegate.
GraphQL Tools is a set of utilities to build and maintain GraphQL schemas and resolvers. It includes schema stitching and delegation capabilities, similar to @graphql-tools/delegate.
Check API Reference for more information about this package; https://www.graphql-tools.com/docs/api/modules/delegate_src
You can also learn more about Schema Delegation in this chapter; https://www.graphql-tools.com/docs/schema-delegation
FAQs
A set of utils for faster development of GraphQL tools
The npm package @graphql-tools/delegate receives a total of 4,381,165 weekly downloads. As such, @graphql-tools/delegate popularity was classified as popular.
We found that @graphql-tools/delegate 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
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.