Updated login operation

This commit is contained in:
Luis Alvarez 2021-05-20 14:37:34 -05:00
parent ff2b12bcf1
commit 1086fce6bd
2 changed files with 22 additions and 13 deletions

View File

@ -1,5 +1,8 @@
import type { ServerResponse } from 'http' import type { ServerResponse } from 'http'
import type { OperationContext } from '@commerce/api/operations' import type {
OperationContext,
OperationOptions,
} from '@commerce/api/operations'
import type { LoginMutation, LoginMutationVariables } from '../../schema' import type { LoginMutation, LoginMutationVariables } from '../../schema'
import type { RecursivePartial } from '../utils/types' import type { RecursivePartial } from '../utils/types'
import concatHeader from '../utils/concat-cookie' import concatHeader from '../utils/concat-cookie'
@ -24,12 +27,13 @@ function loginOperation({ commerce }: OperationContext<Provider>) {
res: ServerResponse res: ServerResponse
}): Promise<LoginResult> }): Promise<LoginResult>
async function login<T extends { result?: any }, V = any>(opts: { async function login<T extends { result?: any }, V = any>(
query: string opts: {
variables: V variables: V
res: ServerResponse
config?: BigcommerceConfig config?: BigcommerceConfig
}): Promise<LoginResult<T>> res: ServerResponse
} & OperationOptions
): Promise<LoginResult<T>>
async function login({ async function login({
query = loginMutation, query = loginMutation,

View File

@ -24,12 +24,13 @@ export type Operations<P extends APIProvider> = {
res: ServerResponse res: ServerResponse
}): Promise<LoginResult> }): Promise<LoginResult>
<T extends { result?: any }, V = any>(opts: { <T extends { result?: any }, V = any>(
query: string opts: {
variables: V variables: V
config?: P['config']
res: ServerResponse res: ServerResponse
config?: P['config'] | undefined } & OperationOptions
}): Promise<LoginResult<T>> ): Promise<LoginResult<T>>
} }
} }
@ -48,3 +49,7 @@ export type AllOperations<P extends APIProvider> = {
export type OperationContext<P extends APIProvider> = { export type OperationContext<P extends APIProvider> = {
commerce: CommerceAPI<P> commerce: CommerceAPI<P>
} }
export type OperationOptions =
| { query: string; url?: never }
| { query?: never; url: string }