Apollo Directive Link
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:
;;; const adminDirectiveLink = directive: 'admin' operation ; const httpLink = uri: '/graphql'; // Configure the ApolloClientconst client = link: cache: ;
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 directivecallback
: a callback function with argsoperation
andforward
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.