
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
graphql-custom-directives
Advanced tools
Create custom graphql directives with the ability to hook the execution of graphql
A collection of custom graphql directives created with Moment, Lodash and Numeral-js.
Checkout graphql-custom-directive for creating your own graphql custom directives.
npm install --save graphql-custom-directives
import {
GraphQLDateDirective,
GraphQLNumberDirective,
GraphQLCurrencyDirective,
GraphQLLowerCaseDirective,
GraphQLUpperCaseDirective,
GraphQLCamelCaseDirective,
GraphQLStartCaseDirective,
GraphQLCapitalizeDirective,
GraphQLKebabCaseDirective,
GraphQLTrimDirective,
GraphQLDefaultToDirective,
GraphQLToLowerDirective,
GraphQLToUpperDirective,
GraphQLTemplateDirective,
GraphQLPhoneDirective,
applySchemaCustomDirectives,
} from 'graphql-custom-directives';
const query = new GraphQLObjectType({
name: 'Query',
fields: {
input: {
type: GraphQLString,
args: {
value: {
type: GraphQLString
}
},
resolve: (source, {value}) => value
}
}
});
const schema = new GraphQLSchema({
directives: [
GraphQLDateDirective,
GraphQLNumberDirective,
GraphQLCurrencyDirective,
GraphQLLowerCaseDirective,
GraphQLUpperCaseDirective,
GraphQLCamelCaseDirective,
GraphQLStartCaseDirective,
GraphQLCapitalizeDirective,
GraphQLKebabCaseDirective,
GraphQLTrimDirective,
GraphQLDefaultToDirective,
GraphQLToLowerDirective,
GraphQLToUpperDirective,
GraphQLPhoneDirective,
GraphQLTemplateDirective
],
query
});
applySchemaCustomDirectives(schema);
graphql(schema, `{ input(value: "test") @upperCase }`)
.then(({ result, errors }) => {
console.log(result); // will print { input: "TEST }
});
is also possible
import { makeExecutableSchema } from 'graphql-tools';
import {
GraphQLDateDirective,
GraphQLNumberDirective,
GraphQLCurrencyDirective,
GraphQLLowerCaseDirective,
GraphQLUpperCaseDirective,
GraphQLCamelCaseDirective,
GraphQLStartCaseDirective,
GraphQLCapitalizeDirective,
GraphQLKebabCaseDirective,
GraphQLTrimDirective,
GraphQLDefaultToDirective,
GraphQLToLowerDirective,
GraphQLToUpperDirective,
GraphQLTemplateDirective,
GraphQLPhoneDirective
applySchemaCustomDirectives
} from 'graphql-custom-directives';
let directives = [
GraphQLDateDirective,
GraphQLNumberDirective,
GraphQLCurrencyDirective,
GraphQLLowerCaseDirective,
GraphQLUpperCaseDirective,
GraphQLCamelCaseDirective,
GraphQLStartCaseDirective,
GraphQLCapitalizeDirective,
GraphQLKebabCaseDirective,
GraphQLTrimDirective,
GraphQLDefaultToDirective,
GraphQLToLowerDirective,
GraphQLToUpperDirective,
GraphQLTemplateDirective,
GraphQLPhoneDirective
]
let schema = makeExecutableSchema(...);
schema._directives.push.apply(schema._directives, directives);
applySchemaCustomDirectives(schema);
Adding date directive to graphql query for formatting the result using Moment.
query {
input(value: "2016-01-01T00:00:00") @date
}
// => { input: "01 Jan 2016 00:00" }
query {
input(value: "2016-01-01T00:00:00") @date(as:"YYYY")
}
// => { input: "2016" }
query {
input(value: "${(new Date).toISOString()}") @date(as:"days ago")
}
// => { input: "0 days ago" }
Adding number directive to graphql query for formatting the result using Numeral-js.
query {
input(value: "1500.404") @number
}
// => { input: "1,500" }
query {
input(value: "-1500.404") @number(as:"(0,0.00)")
}
// => { input: "(1,500.40)" }
query {
input(value: "1500") @currency
}
// => { input: "$1,500)" }
Adding string directive to graphql query for formatting the result using Lodash.
query {
input(value: "FOO BAR") @lowerCase
}
// => { input: "foo bar" }
query {
input(value: "foo bar") @upperCase
}
// => { input: "FOO BAR" }
query {
input(value: "foo bar") @camelCase
}
// => { input: "fooBar" }
query {
input(value: "foo bar") @startCase
}
// => { input: "Foo Bar" }
query {
input(value: "foo bar") @capitalize
}
// => { input: "Foo var" }
query {
input(value: "foo bar") @kebabCase
}
// => { input: "foo-bar" }
query {
input(value: " foo bar ") @trim
}
// => { input: "foo bar" }
query {
input @default(to:"N/A")
}
// => { input: "N/A" }
query {
input(value: "FOO BAR") @toLower
}
// => { input: "foo bar" }
query {
input(value: "foo bar") @toUpper
}
// => { input: "FOO BAR" }
query {
input(value: "foo bar") @template(as:"${input} ${toUpper(input)}")
}
// => { input: "foo bar FOO BAR" }
query {
input(value: " foo bar ") @trim @template(as:"${input} ${input}") @toUpper
}
// => { input: "FOO BAR FOO BAR" }
Adding phone directive to graphql query for formatting the result using libphonenumber-js.
query {
input(value: "+12133734253") @phone
}
// => { input: "+1 213 373 4253" }
query {
input(value: "+12133734253") @phone(as: "national")
}
// => { input: "(213) 373-4253" }
query {
input(value: "+12133734253") @phone(as: "RFC3966")
}
// => { input: "tel:+12133734253" } // URI format
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.
FAQs
Create custom graphql directives with the ability to hook the execution of graphql
The npm package graphql-custom-directives receives a total of 11 weekly downloads. As such, graphql-custom-directives popularity was classified as not popular.
We found that graphql-custom-directives demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.