From 00c42cb8db21326a8df0d72c9a258ffdf08946dd Mon Sep 17 00:00:00 2001 From: Jonny Green Date: Sun, 15 Sep 2024 19:16:26 +0100 Subject: [PATCH 1/4] Prepare for fastify v5 --- index.js | 2 +- lib/filter-schema.js | 6 +++--- package.json | 12 ++++++------ test/auth_on_type-gateway.js | 26 -------------------------- 4 files changed, 10 insertions(+), 36 deletions(-) diff --git a/index.js b/index.js index a7cf15b..1435447 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,7 @@ const plugin = fp( }, { name: 'mercurius-auth', - fastify: '4.x', + fastify: '5.x', dependencies: ['mercurius'] } ) diff --git a/lib/filter-schema.js b/lib/filter-schema.js index a1a25c8..7bb74d7 100644 --- a/lib/filter-schema.js +++ b/lib/filter-schema.js @@ -12,9 +12,9 @@ function filterIntrospectionSchema (app, policy, { applyPolicy: policyFunction } // the filter hook must be the last one to be executed (after all the authContextHook ones) app.ready(err => { - /* istanbul ignore next */ - if (err) throw err - app.graphql.addHook('preExecution', filterGraphQLSchemaHook.bind(app)) + if (!err) { + app.graphql.addHook('preExecution', filterGraphQLSchemaHook.bind(app)) + } }) } diff --git a/package.json b/package.json index aeb83b1..6b53629 100644 --- a/package.json +++ b/package.json @@ -30,8 +30,8 @@ }, "homepage": "https://github.com/mercurius-js/auth", "devDependencies": { - "@mercuriusjs/federation": "^2.0.0", - "@mercuriusjs/gateway": "^1.0.0", + "@mercuriusjs/federation": "^4.0.0", + "@mercuriusjs/gateway": "^4.0.0", "@sinonjs/fake-timers": "^10.0.2", "@types/node": "^20.1.0", "@types/ws": "^8.5.3", @@ -39,8 +39,8 @@ "@typescript-eslint/parser": "^5.30.5", "autocannon": "^7.9.0", "concurrently": "^8.0.1", - "fastify": "^4.2.0", - "mercurius": "^13.0.0", + "fastify": "^5.0.0-alpha.4", + "mercurius": "^15.0.0", "pre-commit": "^1.2.2", "snazzy": "^9.0.0", "standard": "^17.0.0", @@ -50,8 +50,8 @@ "wait-on": "^7.0.1" }, "dependencies": { - "@fastify/error": "^3.0.0", - "fastify-plugin": "^4.0.0", + "@fastify/error": "^4.0.0", + "fastify-plugin": "^5.0.0", "graphql": "^16.2.0" }, "tsd": { diff --git a/test/auth_on_type-gateway.js b/test/auth_on_type-gateway.js index 7e0b9e1..2762501 100644 --- a/test/auth_on_type-gateway.js +++ b/test/auth_on_type-gateway.js @@ -345,32 +345,6 @@ test('gateway - should protect the schema, user object protected', async (t) => '0' ] }, - { - message: 'Failed auth policy check on User', - locations: [ - { - line: 2, - column: 3 - } - ], - path: [ - '_entities', - '1' - ] - }, - { - message: 'Failed auth policy check on User', - locations: [ - { - line: 2, - column: 3 - } - ], - path: [ - '_entities', - '0' - ] - }, { message: 'Failed auth policy check on User', locations: [ From d946f928ef30dfe3798716b96f35275ce9123869 Mon Sep 17 00:00:00 2001 From: Jonny Green Date: Sun, 29 Sep 2024 11:52:54 +0100 Subject: [PATCH 2/4] Replace onReady call with onReady hook --- lib/filter-schema.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/filter-schema.js b/lib/filter-schema.js index 7bb74d7..b5950f6 100644 --- a/lib/filter-schema.js +++ b/lib/filter-schema.js @@ -11,10 +11,8 @@ function filterIntrospectionSchema (app, policy, { applyPolicy: policyFunction } app[kDirectiveGrouping] = [] // the filter hook must be the last one to be executed (after all the authContextHook ones) - app.ready(err => { - if (!err) { - app.graphql.addHook('preExecution', filterGraphQLSchemaHook.bind(app)) - } + app.addHook('onReady', async function () { + app.graphql.addHook('preExecution', filterGraphQLSchemaHook.bind(app)) }) } From a16614f3aaabc83ebd5eb82fc190ce8529a4caae Mon Sep 17 00:00:00 2001 From: Matteo Collina Date: Wed, 2 Oct 2024 08:58:43 +0200 Subject: [PATCH 3/4] Update package.json Co-authored-by: Manuel Spigolon --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6b53629..0c2feb1 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "@typescript-eslint/parser": "^5.30.5", "autocannon": "^7.9.0", "concurrently": "^8.0.1", - "fastify": "^5.0.0-alpha.4", + "fastify": "^5.0.0", "mercurius": "^15.0.0", "pre-commit": "^1.2.2", "snazzy": "^9.0.0", From 49feadc31521b2612f987f733fa7444546aed2ee Mon Sep 17 00:00:00 2001 From: Jonny Green Date: Sat, 12 Oct 2024 10:22:27 +0100 Subject: [PATCH 4/4] Bump Node.js to 20.x+ --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eae3441..5738daa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,7 +5,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - node-version: [18.x, 20.x] + node-version: [20.x, 22.x] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - uses: actions/checkout@v3