A collection of custom GraphQL directives for (Graphene)[https://github.com/graphql-python/graphene]
- Free software: BSD license
- Documentation: https://graphene-custom-directives.readthedocs.org.
- Floor
query {
stringValue(value: "3.14") @floor
floatValue(value: 3.14) @floor
}
// => { stringValue: "3.0", floatValue: 3.0 }
- Ceil
query {
stringValue(value: "3.14") @ceil
floatValue(value: 3.14) @ceil
}
// => { stringValue: "4.0", floatValue: 4.0 }
- Default value:
query {
input @default(to: "YEAH")
}
// => { input: "YEAH" }
- Base64 encode
query {
stringValue(value: "YES") @base64
}
// => { stringValue: "Tm9uZQ==" }
- Uppercase:
query {
input(value: "FOO BAR") @lowercase
}
// => { input: "foo bar" }
- Lowercase:
query {
input(value: "foo BAR") @uppercase
}
// => { input: "FOO BAR" }
- Capitalize:
query {
input(value: "foo BAR") @capitalize
}
// => { input: "Foo Bar" }
- Number formatting
query {
stringValue(value: "3.14") @number(as: "0.4f")
}
// => { stringValue: "3.1400" }
- Currency formatting
query {
stringValue(value: "150000") @currency
}
// => { stringValue: "$150,000" }
- Sample
query {
listValue(value: [1, 2, 3]) @sample(k: 1)
}
// => { listValue: [2] }
- Shuffle
query {
listValue(value: [1, 2, 3]) @shuffle
}
// => { listValue: [2, 1, 3] }
You can also use multiple directives, executed from left to right:
query {
stringValue(value: "3.14") @ceil @number(as: "0.4f")
}
// => { stringValue: "4.0000" }