Skip to content

Commit

Permalink
Merge pull request #24 from thuoe/feature/thu-51-new-directive-currency
Browse files Browse the repository at this point in the history
[THU-51]: @Currency directive
  • Loading branch information
thuoe committed Mar 31, 2024
2 parents 87c639f + 75aa4c6 commit 796d20b
Show file tree
Hide file tree
Showing 8 changed files with 667 additions and 0 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Simple utility library for custom GraphQL schema directives
- [@regex](#regex)
- [@cache](#cache)
- [Overriding in-memory cache](#overriding-in-memory-cache)
- [@currency](#currency)

# Get started

Expand Down Expand Up @@ -203,3 +204,21 @@ You must confirm to this set of function signatures to make this work:
- `get: (key: string) => Promise<string>` Retrieves the value associated with a key from the cache.
- `set: (key: string, value: string) => Promise<void>` Sets a key-value pair in the cache.
- `delete: (key: string) => Promise<boolean>` Deletes a key and its associated value from the cache.

## @currency

`currencyDirective(directiveName?: string)`

You can use the `@currency` directive to fetch the latest exchange rate of a given amount

```graphql
type Car {
make: String
model
price: String @currency(from: "GBP", ttl: "USD")
}
```

The amount can either resolved with the scalar types `String` or `Float`

The valid currency codes to use as part of the directive's arguments can be found [here](./src/types.ts).

0 comments on commit 796d20b

Please sign in to comment.