-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(utils): Add instruments to
wrapFetchWithHooks
(#8456)
* feat(utils): Add instruments to `wrapFetchWithHooks` * chore(dependencies): updated changesets for modified dependencies * changeset * lazy instauments * Add tests --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Arda TANRIKULU <[email protected]>
- Loading branch information
1 parent
b970e06
commit 4528794
Showing
6 changed files
with
84 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@graphql-mesh/utils": patch | ||
--- | ||
dependencies updates: | ||
- Added dependency [`@envelop/instruments@1.0.0-alpha-20250227122402-42e2fa806ec3b7c2936e612924b153a20c8662c3` ↗︎](https://www.npmjs.com/package/@envelop/instruments/v/1.0.0) (to `dependencies`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@graphql-mesh/utils': minor | ||
--- | ||
|
||
Add compatibility with new `Instruments` API of Hive Gateway. See | ||
[Hive Gateway documentation](https://the-guild.dev/graphql/hive/docs/gateway/other-features/custom-plugins#instruments) | ||
for more details. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import type { GraphQLResolveInfo } from 'graphql'; | ||
import { createServerAdapter, Response } from '@whatwg-node/server'; | ||
import { wrapFetchWithHooks, type FetchInstruments } from '../src/wrapFetchWithHooks'; | ||
|
||
describe('Fetch instruments', () => { | ||
it('should wrap fetch instruments', async () => { | ||
await using adapter = createServerAdapter(() => Response.json({ hello: 'world' })); | ||
let receivedExecutionRequest; | ||
const fetchInstruments: FetchInstruments = { | ||
fetch: async ({ executionRequest }, wrapped) => { | ||
receivedExecutionRequest = executionRequest; | ||
await wrapped(); | ||
}, | ||
}; | ||
const wrappedFetch = wrapFetchWithHooks( | ||
[ | ||
({ setFetchFn }) => { | ||
setFetchFn(adapter.fetch); | ||
}, | ||
], | ||
() => fetchInstruments, | ||
); | ||
const executionRequest = {}; | ||
const res = await wrappedFetch('http://localhost:4000', {}, {}, { | ||
executionRequest, | ||
} as GraphQLResolveInfo); | ||
expect(await res.json()).toEqual({ hello: 'world' }); | ||
expect(receivedExecutionRequest).toBe(executionRequest); | ||
}); | ||
}); |
Oops, something went wrong.