Skip to content

ferdelamad/apollo-directives

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Custom graphql/apollo directives

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published