Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

@envelop/core

Package Overview
Dependencies
2
Maintainers
1
Versions
1357
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @envelop/core

This is the core package for Envelop. You can find a complete documentation here: https://github.com/n1ru4l/envelop


Version published
Weekly downloads
483K
decreased by-0.83%
Maintainers
1
Install size
218 kB
Created
Weekly downloads
 

Package description

What is @envelop/core?

@envelop/core is a powerful library for building GraphQL servers with a focus on extensibility and modularity. It provides a plugin system that allows developers to easily add, remove, or customize functionalities in their GraphQL server setup.

What are @envelop/core's main functionalities?

Plugin System

The plugin system allows you to add various plugins to your GraphQL server. In this example, we use the `useSchema` plugin to set up a basic schema.

const { envelop, useSchema } = require('@envelop/core');
const { makeExecutableSchema } = require('@graphql-tools/schema');

const schema = makeExecutableSchema({
  typeDefs: `
    type Query {
      hello: String
    }
  `,
  resolvers: {
    Query: {
      hello: () => 'Hello world!',
    },
  },
});

const getEnveloped = envelop({
  plugins: [useSchema(schema)],
});

const { parse, validate, contextFactory, execute, schema: finalSchema } = getEnveloped();

Custom Plugins

You can create custom plugins to extend the functionality of your GraphQL server. This example shows a custom plugin that logs the operation name whenever an operation is executed.

const { envelop, useLogger } = require('@envelop/core');

const customPlugin = {
  onExecute({ args }) {
    console.log('Executing operation:', args.operationName);
  },
};

const getEnveloped = envelop({
  plugins: [useLogger(), customPlugin],
});

const { execute } = getEnveloped();

Error Handling

The error handling feature allows you to manage and log errors that occur during GraphQL operations. This example demonstrates how to use the `useErrorHandler` plugin to log errors.

const { envelop, useErrorHandler } = require('@envelop/core');

const errorHandlerPlugin = useErrorHandler((errors) => {
  console.error('GraphQL Errors:', errors);
});

const getEnveloped = envelop({
  plugins: [errorHandlerPlugin],
});

const { execute } = getEnveloped();

Other packages similar to @envelop/core

Readme

Source

@envelop/core

This is the core package for Envelop. You can find a complete documentation here: https://github.com/n1ru4l/envelop

Built-in plugins

Keywords

FAQs

Last updated on 16 Oct 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc