Socket
Socket
Sign inDemoInstall

apollo-link-directive

Package Overview
Dependencies
9
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    apollo-link-directive

An Apollo Link to easily add custom directives in your GraphQL queries.


Version published
Maintainers
1
Install size
16.7 kB
Created

Readme

Source

Build Status

Purpose

An Apollo Link to easily add custom directives in your GraphQL queries.

Installation


npm install apollo-link-directive --save
# or
yarn add apollo-link-directive

Usage

Basics

This sample code shows how to use this Apollo Link to change the HttpLink uri with the "admin" directive:


import { from } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { DirectiveLink } from "apollo-link-directive";

const adminDirectiveLink = new DirectiveLink([
  { 
    directive: 'admin', 
    callback: (operation, _forward) => operation.setContext({ uri: '/graphql-admin' })
   },
]);

const httpLink = new HttpLink({
  uri: '/graphql',
});

// Configure the ApolloClient
const client = new ApolloClient({
  link: from([adminDirectiveLink,  httpLink]),
  cache: new InMemoryCache(),
});



this sample code will update all queries having admin directive with uri: /graphql-admin, for example from this query:


const query = gql`
  query luke {
    person @admin {
      name
    }
  }
`;

Options

The options you can pass to DirectiveLink are an array of directives like this:

  • directive: the name of the directive
  • callback: a callback function with args operation and forward
  • remove: an option to remove the directive from the code. Default: true

Thanks

Setting up the project has been largely inspired by the wonderful apollo-link-rest project.

FAQs

Last updated on 09 Oct 2019

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