diff --git a/package.json b/package.json index a1491ac..6643288 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "graphql-custom-directives", - "version": "0.2.13", + "version": "0.2.14", "description": "Create custom graphql directives with the ability to hook the execution of graphql", "main": "dist/index.js", "scripts": { diff --git a/src/directives/currency.js b/src/directives/currency.js index dccd3f4..4694b4a 100644 --- a/src/directives/currency.js +++ b/src/directives/currency.js @@ -15,13 +15,17 @@ exports.GraphQLCurrencyDirective = new GraphQLCustomDirective({ type: GraphQLString, description: 'A currency format given by numeral module', }, + currencySymbol: { + type: GraphQLString, + description: 'A currency symbol to attach to the output (Numeral supports only one currency at a time, so this is an override)' + } }, - resolve(resolve, source, {as}) { + resolve(resolve, source, {as, currencySymbol = ''}) { return resolve().then(input => { const format = as || DEFAULT_CURRENCY_FORMAT; if (format.indexOf('0') !== -1 && !Number.isNaN(Number(input))) { - return numeral(input).format(format) || input; + return `${currencySymbol}${numeral(input).format(format) || input}`; } return input; diff --git a/test/directives/currency.js b/test/directives/currency.js index 971a63a..0d6d21e 100644 --- a/test/directives/currency.js +++ b/test/directives/currency.js @@ -55,4 +55,12 @@ describe('directives/currency', () => { testEqual({directives, query, expected, done}); }); + + it('expected directive to use the supplied currency symbol', done => { + const query = `{ value(input: "10") @currency(as:"0,0.00", currencySymbol: "£") }`, + directives = [GraphQLCurrencyDirective], + expected = {value: '£10.00'}; + + testEqual({directives, query, expected, done}); + }); });