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

@graphql-tools/delegate

Package Overview
Dependencies
Maintainers
4
Versions
1823
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@graphql-tools/delegate

A set of utils for faster development of GraphQL tools

  • 10.1.3-alpha-fdc1ede265110b220a70482db4bb7af63c5b425f
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9M
decreased by-34.74%
Maintainers
4
Weekly downloads
 
Created

What is @graphql-tools/delegate?

@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.

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

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

Other packages similar to @graphql-tools/delegate

FAQs

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