apollo-directives
v1.0.4
Published
Custom graphql/apollo directives
Downloads
66
Maintainers
Readme
apollo-directives
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