{"id":13563159,"url":"https://github.com/lirown/graphql-custom-directives","last_synced_at":"2025-04-03T19:32:26.384Z","repository":{"id":40003304,"uuid":"72479433","full_name":"lirown/graphql-custom-directives","owner":"lirown","description":"A collection of custom graphql directives","archived":false,"fork":false,"pushed_at":"2024-04-30T11:53:47.000Z","size":201,"stargazers_count":110,"open_issues_count":4,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-02T12:02:52.172Z","etag":null,"topics":["graphql","graphql-custom-directive","graphql-directive"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lirown.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-10-31T21:27:35.000Z","updated_at":"2024-06-04T00:11:27.000Z","dependencies_parsed_at":"2023-11-12T10:27:48.301Z","dependency_job_id":"9d4f0fb5-360c-4187-9f4a-224a259130ea","html_url":"https://github.com/lirown/graphql-custom-directives","commit_stats":{"total_commits":92,"total_committers":7,"mean_commits":"13.142857142857142","dds":0.5652173913043479,"last_synced_commit":"5b2011f01365167c7d5f368c964c0c196ecf5a58"},"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lirown%2Fgraphql-custom-directives","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lirown%2Fgraphql-custom-directives/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lirown%2Fgraphql-custom-directives/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lirown%2Fgraphql-custom-directives/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lirown","download_url":"https://codeload.github.com/lirown/graphql-custom-directives/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247065407,"owners_count":20877769,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["graphql","graphql-custom-directive","graphql-directive"],"created_at":"2024-08-01T13:01:15.768Z","updated_at":"2025-04-03T19:32:26.105Z","avatar_url":"https://github.com/lirown.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","\u003ca name=\"JavaScript\"\u003e\u003c/a\u003eJavaScript"],"sub_categories":[],"readme":"# graphql-custom-directives\n[![Build Status](https://travis-ci.org/lirown/graphql-custom-directives.svg?branch=master)](https://travis-ci.org/lirown/graphql-custom-directives)\n[![Coverage Status](https://coveralls.io/repos/github/lirown/graphql-custom-directives/badge.svg?branch=master)](https://coveralls.io/github/lirown/graphql-custom-directives?branch=master)\n[![npm version](https://badge.fury.io/js/graphql-custom-directives.svg)](https://badge.fury.io/js/graphql-custom-directives)\n[![Dependency Status](https://david-dm.org/lirown/graphql-custom-directives.svg)](https://david-dm.org/lirown/graphql-custom-directives)\n[![Known Vulnerabilities](https://snyk.io/test/github/lirown/graphql-custom-directives/e2453e0c95d82fb876c1da228920bf7966a10af8/badge.svg)](https://snyk.io/test/github/lirown/graphql-custom-directives/e2453e0c95d82fb876c1da228920bf7966a10af8)\n[![License](http://img.shields.io/:license-mit-blue.svg)](http://doge.mit-license.org)\n\nA collection of custom graphql directives created with [Moment](https://github.com/moment/moment), [Lodash](https://github.com/lodash/lodash) and [Numeral-js](https://github.com/adamwdraper/Numeral-js).\n\nCheckout [graphql-custom-directive](https://github.com/lirown/graphql-custom-directive) for creating your own graphql custom directives.\n\n### Install\n```\nnpm install --save graphql-custom-directives\n```\n\n\n### Usage\n```javascript\nimport {\n  GraphQLDateDirective,\n  GraphQLNumberDirective,\n  GraphQLCurrencyDirective,\n  GraphQLLowerCaseDirective,\n  GraphQLUpperCaseDirective,\n  GraphQLCamelCaseDirective,\n  GraphQLStartCaseDirective,\n  GraphQLCapitalizeDirective,\n  GraphQLKebabCaseDirective,\n  GraphQLTrimDirective,\n  GraphQLDefaultToDirective,\n  GraphQLToLowerDirective,\n  GraphQLToUpperDirective,\n  GraphQLTemplateDirective,\n  GraphQLPhoneDirective,\n  applySchemaCustomDirectives,\n} from 'graphql-custom-directives';\n\nconst query = new GraphQLObjectType({\n   name: 'Query',\n   fields: {\n     input: {\n       type: GraphQLString,\n       args: {\n         value: {\n           type: GraphQLString\n         }\n       },\n       resolve: (source, {value}) =\u003e value\n     }\n   }\n});\n\nconst schema = new GraphQLSchema({\n  directives: [\n    GraphQLDateDirective,\n    GraphQLNumberDirective,\n    GraphQLCurrencyDirective,\n    GraphQLLowerCaseDirective,\n    GraphQLUpperCaseDirective,\n    GraphQLCamelCaseDirective,\n    GraphQLStartCaseDirective,\n    GraphQLCapitalizeDirective,\n    GraphQLKebabCaseDirective,\n    GraphQLTrimDirective,\n    GraphQLDefaultToDirective,\n    GraphQLToLowerDirective,\n    GraphQLToUpperDirective,\n    GraphQLPhoneDirective,\n    GraphQLTemplateDirective\n  ],\n  query\n});\n\napplySchemaCustomDirectives(schema);\n\ngraphql(schema, `{ input(value: \"test\") @upperCase }`)\n  .then(({ result, errors }) =\u003e {\n     console.log(result); // will print { input: \"TEST }\n  });\n```\n\n### Using with apollo\n\nis also possible\n\n```javascript\nimport { makeExecutableSchema } from 'graphql-tools';\nimport {\n  GraphQLDateDirective,\n  GraphQLNumberDirective,\n  GraphQLCurrencyDirective,\n  GraphQLLowerCaseDirective,\n  GraphQLUpperCaseDirective,\n  GraphQLCamelCaseDirective,\n  GraphQLStartCaseDirective,\n  GraphQLCapitalizeDirective,\n  GraphQLKebabCaseDirective,\n  GraphQLTrimDirective,\n  GraphQLDefaultToDirective,\n  GraphQLToLowerDirective,\n  GraphQLToUpperDirective,\n  GraphQLTemplateDirective,\n  GraphQLPhoneDirective\n  applySchemaCustomDirectives\n} from 'graphql-custom-directives';\n\nlet directives = [\n    GraphQLDateDirective,\n    GraphQLNumberDirective,\n    GraphQLCurrencyDirective,\n    GraphQLLowerCaseDirective,\n    GraphQLUpperCaseDirective,\n    GraphQLCamelCaseDirective,\n    GraphQLStartCaseDirective,\n    GraphQLCapitalizeDirective,\n    GraphQLKebabCaseDirective,\n    GraphQLTrimDirective,\n    GraphQLDefaultToDirective,\n    GraphQLToLowerDirective,\n    GraphQLToUpperDirective,\n    GraphQLTemplateDirective,\n    GraphQLPhoneDirective\n  ]\n\nlet schema = makeExecutableSchema(...);\n\nschema._directives.push.apply(schema._directives, directives);\napplySchemaCustomDirectives(schema);\n\n```\n\n### Date formatting directives\n\nAdding date directive to graphql query for formatting the result using [Moment](https://github.com/moment/moment).\n\n- Using default date format:\n```javascript\n  query {\n    input(value: \"2016-01-01T00:00:00\") @date\n  }\n  // =\u003e { input: \"01 Jan 2016 00:00\" }\n```\n- Using specific moment format:\n```javascript\n  query {\n    input(value: \"2016-01-01T00:00:00\") @date(as:\"YYYY\")\n  }\n// =\u003e { input: \"2016\" }\n```\n- Using days ago format\n```javascript\n  query {\n    input(value: \"${(new Date).toISOString()}\") @date(as:\"days ago\")\n  }\n  // =\u003e { input: \"0 days ago\" }\n```\n\n### Number formatting directives\n\nAdding number directive to graphql query for formatting the result using [Numeral-js](https://github.com/adamwdraper/Numeral-js).\n\n- Using default format:\n```javascript\n  query {\n    input(value: \"1500.404\") @number\n  }\n  // =\u003e { input: \"1,500\" }\n```\n- Using specific numeral format:\n```javascript\n  query {\n    input(value: \"-1500.404\") @number(as:\"(0,0.00)\")\n  }\n  // =\u003e { input: \"(1,500.40)\" }\n```\n-  Using default currency format:\n```javascript\n  query {\n    input(value: \"1500\") @currency\n  }\n  // =\u003e { input: \"$1,500)\" }\n```\n\n### String formatting directives\n\nAdding string directive to graphql query for formatting the result using [Lodash](https://github.com/lodash/lodash).\n\n- Using lowerCase directive:\n\n```javascript\n  query {\n    input(value: \"FOO BAR\") @lowerCase\n  }\n  // =\u003e { input: \"foo bar\" }\n```\n\n- Using upperCase directive:\n\n```javascript\n  query {\n    input(value: \"foo bar\") @upperCase\n  }\n  // =\u003e { input: \"FOO BAR\" }\n```\n\n- Using camelCase directive:\n\n```javascript\n  query {\n    input(value: \"foo bar\") @camelCase\n  }\n  // =\u003e { input: \"fooBar\" }\n```\n\n- Using startCase directive:\n\n```javascript\n  query {\n    input(value: \"foo bar\") @startCase\n  }\n  // =\u003e { input: \"Foo Bar\" }\n```\n\n- Using capitalize directive:\n\n```javascript\n  query {\n    input(value: \"foo bar\") @capitalize\n  }\n  // =\u003e { input: \"Foo var\" }\n```\n\n- Using kebabCase directive:\n\n```javascript\n  query {\n    input(value: \"foo bar\") @kebabCase\n  }\n  // =\u003e { input: \"foo-bar\" }\n```\n\n- Using trim directive:\n\n```javascript\n  query {\n    input(value: \"  foo bar  \") @trim\n  }\n  // =\u003e { input: \"foo bar\" }\n```\n\n- Using default directive:\n\n```javascript\n  query {\n    input @default(to:\"N/A\")\n  }\n  // =\u003e { input: \"N/A\" }\n```\n\n- Using toLower directive:\n\n```javascript\n  query {\n    input(value: \"FOO BAR\") @toLower\n  }\n  // =\u003e { input: \"foo bar\" }\n```\n\n- Using toUpper directive:\n\n```javascript\n  query {\n    input(value: \"foo bar\") @toUpper\n  }\n  // =\u003e { input: \"FOO BAR\" }\n```\n\n- Using template directive:\n\n```javascript\n  query {\n    input(value: \"foo bar\") @template(as:\"${input} ${toUpper(input)}\")\n  }\n  // =\u003e { input: \"foo bar FOO BAR\" }\n```\n\n- Using template together with trim and toUpper directives:\n\n```javascript\n  query {\n    input(value: \"  foo bar   \") @trim @template(as:\"${input} ${input}\") @toUpper\n  }\n  // =\u003e { input: \"FOO BAR FOO BAR\" }\n```\n\n### Phone formatting directives\n\nAdding phone directive to graphql query for formatting the result using [libphonenumber-js](https://github.com/catamphetamine/libphonenumber-js).\n\n- Using default international format:\n```javascript\n  query {\n    input(value: \"+12133734253\") @phone\n  }\n  // =\u003e { input: \"+1 213 373 4253\" }\n```\n- Using specific format:\n```javascript\n  query {\n    input(value: \"+12133734253\") @phone(as: \"national\")\n  }\n// =\u003e { input: \"(213) 373-4253\" }\n  query {\n    input(value: \"+12133734253\") @phone(as: \"RFC3966\")\n  }\n// =\u003e { input: \"tel:+12133734253\" } // URI format\n```\n\n\n### License\n```\nThe MIT License (MIT)\n\nCopyright (c) 2016 Lirown\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flirown%2Fgraphql-custom-directives","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flirown%2Fgraphql-custom-directives","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flirown%2Fgraphql-custom-directives/lists"}