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(find/findOne): allow fetch options as third param #360

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 docs/content/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Get entries. Returns entries matching the query filters (see [parameters](https:
- **Arguments:**
- contentType: `string`
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24)
- fetchOptions?: [`FetchOptions`](https://github.com/unjs/ohmyfetch/blob/main/src/fetch.ts#L26)
- **Returns:** `Promise<T>`

```vue
Expand All @@ -69,6 +70,7 @@ Returns an entry by `id`.
- contentType: `string`
- id?: `string | number | Strapi4RequestParams`
- params?: [`Strapi4RequestParams`](https://github.com/nuxt-modules/strapi/blob/dev/src/runtime/types/v4.d.ts#L24)
- fetchOptions?: [`FetchOptions`](https://github.com/unjs/ohmyfetch/blob/main/src/fetch.ts#L26)
- **Returns:** `Promise<T>`

```vue
Expand Down
9 changes: 5 additions & 4 deletions src/runtime/composables-v4/useStrapi4.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Strapi4RequestParams } from '../types/v4'
import type { FetchOptions } from 'ofetch'
import { useStrapiVersion, useStrapiClient } from '#imports'

/**
Expand All @@ -19,8 +20,8 @@ export const useStrapi4 = () => {
* @param {Strapi4RequestParams} params? - Query parameters
* @returns Promise<T>
*/
const find = <T>(contentType: string, params?: Strapi4RequestParams): Promise<T> => {
return client(`/${contentType}`, { method: 'GET', params })
const find = <T>(contentType: string, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise<T> => {
return client(`/${contentType}`, { method: 'GET', params, ...fetchOptions })
}

/**
Expand All @@ -31,7 +32,7 @@ export const useStrapi4 = () => {
* @param {Strapi4RequestParams} params? - Query parameters
* @returns Promise<T>
*/
const findOne = <T>(contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams): Promise<T> => {
const findOne = <T>(contentType: string, id?: string | number | Strapi4RequestParams, params?: Strapi4RequestParams, fetchOptions?: FetchOptions): Promise<T> => {
if (typeof id === 'object') {
params = id
// @ts-ignore
Expand All @@ -40,7 +41,7 @@ export const useStrapi4 = () => {

const path = [contentType, id].filter(Boolean).join('/')

return client(path, { method: 'GET', params })
return client(path, { method: 'GET', params, ...fetchOptions })
}

/**
Expand Down