Skip to content

Commit b8806d0

Browse files
committed
feat(currency): validate only fields with scalar type string
1 parent cbf0cff commit b8806d0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/directives/currency.ts

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ const currencyDirective = (directiveName: string = 'currency') => {
2020
return {
2121
...fieldConfig,
2222
resolve: async (source, args, context, info) => {
23+
const { fieldName, returnType } = info
24+
const type = returnType.toString()
25+
if (type !== 'String') {
26+
throw new GraphQLError(`Unable to validate field "${fieldName}" of type ${type}. @currency directive can only be used on scalar type String`)
27+
}
2328
const value = await resolve(source, args, context, info)
2429
try {
2530
const response = await fetch(`https://www.google.com/search?q=${value}+${from}+to+${to}+&hl=en`)

0 commit comments

Comments
 (0)