Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export request init extended type #812

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/entrypoints/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ export {
type Variables,
}
export default request

export { RequestInitExtended } from '../legacy/helpers/types.js'
8 changes: 4 additions & 4 deletions src/legacy/helpers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ export type RequestOptions<V extends Variables = Variables, T = unknown> =

export type ResponseMiddleware = (
response: GraphQLClientResponse<unknown> | ClientError | Error,
request: RequestExtendedInit,
request: RequestInitExtended,
) => MaybePromise<void>

export type RequestMiddleware<V extends Variables = Variables> = (
request: RequestExtendedInit<V>,
) => RequestExtendedInit | Promise<RequestExtendedInit>
request: RequestInitExtended<V>,
) => RequestInitExtended | Promise<RequestInitExtended>

export type RequestExtendedInit<V extends Variables = Variables> = RequestInit & {
export type RequestInitExtended<V extends Variables = Variables> = RequestInit & {
url: string
operationName?: string
variables?: V
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy/middleware.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setupMockServer } from './__helpers.js'

const ctx = setupMockServer()

test(`throwing an error in response middleware is not swalled`, async () => {
test(`throwing an async error in response middleware is awaited`, async () => {
const client = new GraphQLClient(ctx.url, {
// eslint-disable-next-line
responseMiddleware: async () => {
Expand Down