Modif
GraphQL API Playground with cascade-like operations
Install / Use
/learn @pedropalhari/ModifREADME
modif (🍖👉🥪)
modif is a small GraphQL API with transform capabilities. It takes a string input and outputs a string. Always.
TL;DR
- Go play with it at https://modif.palhari.dev
Examples
Some cool examples to start you by:
# Operation
query UppercaseString($value: String!) {
modify(value: $value) {
uppercase {
value
}
}
}
# Variables
{
"value": "i'm a lowercase string"
}
# Operation
query GetEmailAddressDomain(
$value: String!
$arg1: String!
$concatArg1: String!
) {
modify(value: $value) {
starts(arg1: $arg1) {
removeWhiteSpace {
concat(arg1: $concatArg1) {
value
}
}
}
}
}
# Variables
{
"value": "My email address is pedro@palhari.dev",
"arg1": "@",
"concatArg1": " is the email address' domain"
}
- Get the address of a CEP (Brazilian-specific Zip Code)
- Using https://viacep.com.br/
# Operation
query GetStreetNameFromCEP(
$value: String!
$arg1: String!
$arg2: String!
$concatArg1: String!
) {
modify(value: $value) {
onlyNumbers {
viaCEP {
between(arg1: $arg1, arg2: $arg2) {
concat(arg1: $concatArg1) {
value
}
}
}
}
}
}
# Variables
{
"value": "My house is located at 15370-496",
"arg1": "logradouro:",
"arg2": "|",
"concatArg1": " is the street I live"
}
How does it work?
Using GraphQL attribute resolving as a runtime recursive transformer of the input. The GraphQL server is made of a single Object called ModifierObject.
Inside ModifierObject all the modifiers are declared and return their own ModifierObject. The only static variable is the value, a string.
Attributes are resolved at runtime using an obscure function attribute called length. This allows me to generate the arguments for this function when the server boots up.
You can check all of that, under great detail and in a manifesto-kinda way of programming on graphql/GraphQLModifiers.ts.
Contributing
Have a great idea or want to add more modifiers to it? Check out modifiers/StringModifiers.ts and make sure you read the concept on graphql/GraphQLModifiers.ts to know what I want this to eventually end.
Running locally
- Clone the repo
yarn- Either
node pm2.jsoryarn dev:g- The latter is prefered as it has
nodemonand--enable-source-mapscapabilities. - A server will spawn under
http://localhost:6780, navigate to it to query the API
- The latter is prefered as it has
Early FAQ
- Hey, why don't you use
Xinstead of Apollo Studio Sandbox?
I like the Sandbox. It's visually great, let me do a lot of work visually.
- Why can't I do
Y?
Very very early stage toy. But check Contributing up above and make yourself at home.
