Skip to content

Commit

Permalink
major: upgrade to fastify v5 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eomm committed Sep 19, 2024
1 parent a5aeec1 commit 15d4c13
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ on:

jobs:
test:
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v3
uses: fastify/workflows/.github/workflows/plugins-ci.yml@v5.0.0
with:
lint: true
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,5 @@ dist
.tern-port
.vscode/
package-lock.json

# Wallaby.js configuration
wallaby.conf.js
.tap
asd*
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ package-lock.json
wallaby.conf.js
test/*
.github/*
.eslintrc
.eslintrc
.tap
asd*
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# mercurius-logging

[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![ci](https://github.com/Eomm/mercurius-logging/actions/workflows/ci.yml/badge.svg)](https://github.com/Eomm/mercurius-logging/actions/workflows/ci.yml)
[![npm](https://img.shields.io/npm/v/mercurius-logging)](https://www.npmjs.com/package/mercurius-logging)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

This plugin add a Log with all the GraphQL details you need.

Expand Down Expand Up @@ -112,6 +113,13 @@ Otherwise, this plugin will ignore the request.
npm install mercurius-logging
```

### Compatibility

| Plugin version | Fastify version |
| ------------- |:---------------:|
| `^2.0.0` | `^5.0.0` |
| `^1.0.0` | `^4.0.0` |

## Usage

```js
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function readOps (document, operation, opts) {
const plugin = fp(mercuriusLogging,
{
name: 'mercurius-logging',
fastify: '4.x',
fastify: '^5.x',
dependencies: ['mercurius']
}
)
Expand Down
17 changes: 8 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"lint": "standard && npm run lint:typescript",
"lint:fix": "standard --fix",
"lint:typescript": "standard --parser @typescript-eslint/parser --plugin @typescript-eslint/eslint-plugin types/**/*.ts",
"test": "c8 --100 ava && tsd",
"test:unit": "ava",
"test": "tap --show-full-coverage && tsd",
"test:unit": "tap --show-full-coverage",
"test:types": "tsd"
},
"repository": {
Expand All @@ -35,18 +35,17 @@
"homepage": "https://github.com/Eomm/mercurius-logging#readme",
"devDependencies": {
"@types/node": "^22.0.0",
"@typescript-eslint/eslint-plugin": "^6.4.0",
"@typescript-eslint/parser": "^6.4.0",
"ava": "^5.3.1",
"c8": "^10.1.2",
"fastify": "^4.4.0",
"@typescript-eslint/eslint-plugin": "^7.0.0",
"@typescript-eslint/parser": "^7.0.0",
"fastify": "^5.0.0",
"graphql": "^16.8.0",
"mercurius": "^14.0.0",
"mercurius": "^15.0.0",
"split2": "^4.1.0",
"standard": "^17.0.0",
"tap": "^21.0.0",
"tsd": "^0.31.0"
},
"dependencies": {
"fastify-plugin": "^4.2.0"
"fastify-plugin": "^5.0.0"
}
}
12 changes: 6 additions & 6 deletions test/handle-reply-undefined.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const test = require('ava')
const { test } = require('tap')
const { buildApp, jsonLogger } = require('./_helper')

test('should handle without logging when context.reply is undefined', async (t) => {
Expand All @@ -24,7 +24,7 @@ test('should handle without logging when context.reply is undefined', async (t)
url: '/custom-endpoint'
})

t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -39,9 +39,9 @@ test('should log when using graphql mercurius decorator providing reply object i

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.graphql, {
t.same(line.req, undefined)
t.same(line.reqId, 'req-1')
t.same(line.graphql, {
queries: ['add', 'add', 'echo', 'counter']
})
})
Expand All @@ -64,7 +64,7 @@ test('should log when using graphql mercurius decorator providing reply object i
url: '/custom-endpoint'
})

t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand Down
18 changes: 9 additions & 9 deletions test/issue-22.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
'use strict'

const test = require('ava')
const { test } = require('tap')
const { buildApp, jsonLogger } = require('./_helper')

test('should deal GET request', async (t) => {
t.plan(4)

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.graphql, {
t.same(line.req, undefined)
t.same(line.reqId, 'req-1')
t.same(line.graphql, {
queries: ['add', 'add', 'echo', 'counter']
})
})
Expand All @@ -30,7 +30,7 @@ test('should deal GET request', async (t) => {
url: '/graphql',
query: { query }
})
t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -40,7 +40,7 @@ test('should deal GET request', async (t) => {
})
})

test('should log the whole request when operationName is set', async (t) => {
test('should log the whole request when operationName same set', async (t) => {
t.plan(3)

const query = `
Expand All @@ -56,8 +56,8 @@ test('should log the whole request when operationName is set', async (t) => {

const stream = jsonLogger(
line => {
t.is(line.reqId, 'req-1')
t.deepEqual(line.graphql, {
t.same(line.reqId, 'req-1')
t.same(line.graphql, {
queries: ['add', 'add', 'add', 'add'],
operationName: 'baam',
body: query,
Expand All @@ -81,5 +81,5 @@ test('should log the whole request when operationName is set', async (t) => {
}
})

t.deepEqual(response.json(), { data: { c: 5, d: 5 } })
t.same(response.json(), { data: { c: 5, d: 5 } })
})
62 changes: 31 additions & 31 deletions test/logMessage.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
'use strict'

const test = require('ava')
const { test } = require('tap')
const { buildApp, jsonLogger } = require('./_helper')

test('should log without msg when logMessage is undefined', async (t) => {
t.plan(5)

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.msg, undefined)
t.deepEqual(line.graphql, {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -32,7 +32,7 @@ test('should log without msg when logMessage is undefined', async (t) => {
url: '/graphql',
body: JSON.stringify({ query })
})
t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -47,10 +47,10 @@ test('should log without msg when logMessage is\'nt a valid function', async (t)

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.msg, undefined)
t.deepEqual(line.graphql, {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -71,7 +71,7 @@ test('should log without msg when logMessage is\'nt a valid function', async (t)
url: '/graphql',
body: JSON.stringify({ query })
})
t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -88,10 +88,10 @@ test('should log without msg using a logMessage function returning an undefined

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.msg, undefined)
t.deepEqual(line.graphql, {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -112,7 +112,7 @@ test('should log without msg using a logMessage function returning an undefined
url: '/graphql',
body: JSON.stringify({ query })
})
t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -129,10 +129,10 @@ test('should log without msg using a logMessage function throwing an error', asy

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.msg, undefined)
t.deepEqual(line.graphql, {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, undefined)
t.same(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -153,7 +153,7 @@ test('should log without msg using a logMessage function throwing an error', asy
url: '/graphql',
body: JSON.stringify({ query })
})
t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -170,10 +170,10 @@ test('should log with msg using a logMessage function returning a string', async

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.msg, 'This is a request made with method POST')
t.deepEqual(line.graphql, {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, 'This is a request made with method POST')
t.same(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -194,7 +194,7 @@ test('should log with msg using a logMessage function returning a string', async
url: '/graphql',
body: JSON.stringify({ query })
})
t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand All @@ -211,10 +211,10 @@ test('should log with msg using a logMessage function returning an array', async

const stream = jsonLogger(
line => {
t.is(line.req, undefined)
t.is(line.reqId, 'req-1')
t.deepEqual(line.msg, 'This is a request made with method POST by foobar')
t.deepEqual(line.graphql, {
t.equal(line.req, undefined)
t.equal(line.reqId, 'req-1')
t.same(line.msg, 'This is a request made with method POST by foobar')
t.same(line.graphql, {
operationName: 'logMe',
queries: ['add', 'add', 'echo', 'counter']
})
Expand All @@ -235,7 +235,7 @@ test('should log with msg using a logMessage function returning an array', async
url: '/graphql',
body: JSON.stringify({ query })
})
t.deepEqual(response.json(), {
t.same(response.json(), {
data: {
four: 4,
six: 6,
Expand Down
Loading

0 comments on commit 15d4c13

Please sign in to comment.