apollo-directives

1.0.4 • Public • Published

apollo-directives

npm package

Custom graphQL directives for Apollo

🎉 Installation

npm i apollo-directives
# or 
yarn add apollo-directives

📙 Directives

  renameField, camelCase, capitalize, lowerFirst, toLower, toUpper, trim, upperFirst

✍ Example Usage

Add schemaDirectives to your server

const { ApolloServer } = require('apollo-server-express')
const { renameField, upperFirst, toUpper, toLower, trim, } = require('apollo-directives')
 
const server = new ApolloServer({
  schemaDirectives: {
    renameField,
    upperFirst,
    toUpper,
    toLower,
    trim
  }
  ...
  context,
  typeDefs,
  resolvers,
  dataSources,
});

Include and use directives in your typeDefs

const { gql } = require('apollo-server-express');
 
const typeDefs = gql`
  directive @renameField(name: String!) on FIELD_DEFINITION
  directive @upperFirst on FIELD_DEFINITION
  directive @toLower on FIELD_DEFINITION
  directive @trim on FIELD_DEFINITION
  directive @toUpper on FIELD_DEFINITION
 
  type Person {
    myCustomField: String! @renameField(name: "original_api_field_name")
    firstName: String! @upperFirst
    lastName: String! @upperFirst
    title: String! @toUpper
    address: String! @trim
    state: String! @toLower
  }
`;

👷 Work in progess

Warning: This library is still a WIP. This is a beta version.

❓ Questions/Comments

Feel free to reach out ~ ferdelamad

Package Sidebar

Install

npm i apollo-directives

Weekly Downloads

7

Version

1.0.4

License

ISC

Unpacked Size

16.7 kB

Total Files

4

Last publish

Collaborators

  • ferdelamad