Skip to content

Commit

Permalink
Merge pull request #30 from thuoe/next
Browse files Browse the repository at this point in the history
Release `next`: 2024/05/02
  • Loading branch information
thuoe authored May 2, 2024
2 parents f633c23 + f8d14c4 commit 486c078
Show file tree
Hide file tree
Showing 11 changed files with 462 additions and 85 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
dist
bundle
*.log
48 changes: 46 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Simple utility library for custom GraphQL schema directives
- [@cache](#cache)
- [Overriding in-memory cache](#overriding-in-memory-cache)
- [@currency](#currency)
- [@log](#log)
- [Logging to file](#logging-to-file)

# Get started

Expand Down Expand Up @@ -215,10 +217,52 @@ You can use the `@currency` directive to fetch the latest exchange rate of a giv
type Car {
make: String
model: String
price: String @currency(from: "GBP", to: "USD")
price: String @currency(from: GBP, to: USD)
}
```

The amount can either resolved with the scalar types `String` or `Float`
The field can either be resolved with 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).

## @log

`logDirective({ directiveName, filePath }?: { directiveName?: string, filePath?: string })`

Use the `@log` directive to log fields, queries and mutations once they are resolved.

For example, this graphql schema with the directive on the query:

```graphql
type User {
firstName: String
lastName: String
age: Int
amount: String
}

type Query {
user(firstName: String!): User @log(level: INFO)
}
```

Will log to the console in the following format:

`[<TIMESTAMP>] [INFO] @log - Operation Type: query, Arguments: [{"firstName":"Eddie"}], Return Type: User`

The following log levels are valid:

- `INFO`
- `DEBUG`
- `WARN`
- `ERROR`

### Logging to file

In order to migrate logs to a custom log file, you can define a filepath with the appropriate file name:

```typescript
const { logDirectiveTypeDefs, logDirectiveTransformer } = logDirective({
filePath: path.join(__dirname, 'logs', 'application.log')
})
```
150 changes: 135 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,17 @@
"build:server": "tsc --project tsconfig.server.json",
"dev": "nodemon --project tsconfig.server.json server/index.ts",
"lint": "eslint .",
"test": "jest",
"test": "jest --silent",
"test:watch": "npm run test -- --watch test/*.ts",
"prepare": "npm run build:prod",
"release": "semantic-release"
},
"dependencies": {
"@graphql-tools/schema": "^10.0.2",
"@graphql-tools/utils": "^10.0.13",
"cheerio": "^1.0.0-rc.12",
"graphql": "^16.8.1"
"graphql": "^16.8.1",
"log4js": "^6.9.1"
},
"devDependencies": {
"@apollo/server": "^4.10.0",
Expand Down
Loading

0 comments on commit 486c078

Please sign in to comment.