graphql-custom-directive
A custom directive for GraphQL with the ability to hook the query execution.
Install
npm install --save graphql-custom-directive
Usage
; ; ; // Define a directive that upper case the result const GraphQLCustomDuplicateDirective = name: 'toUpperCase' description: 'change the case of a string to uppercase' locations: DirectiveLocationFIELD { return ; }; const schema = directives: GraphQLCustomDuplicateDirective query: name: 'Query' fields: value: type: GraphQLString 'test' ; ; ;
Options
Examples
This show the ability to configure directive on the query side or in the schema side
; ; ; // Define a directive that duplicates the input const GraphQLCustomDuplicateDirective = name: 'duplicate' description: 'duplicate the string sperating them with space' locations: DirectiveLocationFIELD args: by: type: GraphQLInt description: 'the times to duplicate the string' { return ; }; // Use directive in a query const schema = directives: GraphQLCustomDuplicateDirective query: name: 'Query' fields: input: type: GraphQLString args: value: type: GraphQLString value ; ; ; // Or use the directive in a schema const schema2 = directives: GraphQLCustomDuplicateDirective query: name: 'Query' fields: input: type: GraphQLString args: value: type: GraphQLString directives: duplicate: // directive name by: 2 // directive args value ; ; ;
License
The MIT License (MIT)
Copyright (c) 2016 Lirown
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.