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

fix: custom query and mutation arguments passing #1509

Merged
merged 1 commit into from
Apr 3, 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
5 changes: 5 additions & 0 deletions .changeset/nine-berries-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@vue-storefront/magento-sdk": patch
---

[FIXED] Correctly passing properties and options to `customQuery` and `customMutation` SDK methods. Previously, the `customHeaders` option was not being passed properly. Now, all options will be properly passed to the `customQuery` and `customMutation` methods.
4 changes: 2 additions & 2 deletions packages/api-client/__tests__/mockData/api/storeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const STORE_CONFIG_MOCK_RESP = {
configurable_thumbnail_source: "parent",
copyright: "Copyright Β© 2013-present Magento, Inc. All rights reserved.",
default_description: null,
default_display_currency_code: "USD",
default_display_currency_code: "EUR",
default_keywords: null,
default_title: "Magento Commerce",
grid_per_page: 12,
Expand All @@ -24,7 +24,7 @@ const STORE_CONFIG_MOCK_RESP = {
list_mode: "grid-list",
list_per_page: 10,
list_per_page_values: "5,10,15,20,25",
locale: "en_US",
locale: expect.any(String),
logo_alt: null,
logo_height: null,
logo_width: null,
Expand Down
8 changes: 6 additions & 2 deletions packages/sdk/__tests__/unit/customMutation.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { describeGroup } from './__config__/jest.setup';
import { client } from '../../src';
import { MethodBaseOptions } from '../../src/types';

const PARAMS_MOCK = { mutation: '{ __typename }', mutationVariables: {} };
const PARAMS_MOCK = { mutation: '{ __typename }', mutationVariables: {}, customHeaders: {} };
const OPTIONS_MOCK = { clientConfig: {}, customHeaders: {} } as MethodBaseOptions;
const RESPONSE_MOCK = { data: { data: 'some_data', error: null } };
const ERROR_MOCK = new Error('error');
Expand All @@ -24,7 +24,11 @@ describe(describeGroup('customMutation'), () => {
it('makes a call to API Middleware with proper params and options', async () => {
await customMutation(PARAMS_MOCK, OPTIONS_MOCK);

expect(client.post).toBeCalledWith('customMutation', [expect.objectContaining(PARAMS_MOCK), {}], {});
expect(client.post).toBeCalledWith(
'customMutation',
{ customHeaders: {}, mutation: '{ __typename }', mutationVariables: {} },
{},
);
});

it('extracts and returns a response', async () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/sdk/__tests__/unit/customQuery.unit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ describe(describeGroup('customQuery'), () => {
it('makes a call to API Middleware with proper params and options', async () => {
await customQuery(PARAMS_MOCK, OPTIONS_MOCK);

expect(client.post).toBeCalledWith('customQuery', [expect.objectContaining(PARAMS_MOCK), {}], {});
expect(client.post).toBeCalledWith(
'customQuery',
{ customHeaders: {}, query: '{ __typename }', queryVariables: {} },
{},
);
});

it('extracts and returns a response', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/methods/customMutation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export async function customMutation<RES extends CustomMutationResponse<any>, IN
return new AxiosRequestSender(client)
.setUrl('customMutation')
.setMethod('POST')
.setProps([params, options?.customHeaders])
.setProps({ ...params, customHeaders: options?.customHeaders })
.setConfig(options?.clientConfig)
.send<RES>();
}
2 changes: 1 addition & 1 deletion packages/sdk/src/methods/customQuery/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export async function customQuery<RES extends CustomQueryResponse<any>, INPUT ex
return new AxiosRequestSender(client)
.setUrl('customQuery')
.setMethod('POST')
.setProps([params, options?.customHeaders])
.setProps({ ...params, customHeaders: options?.customHeaders })
.setConfig(options?.clientConfig)
.send<RES>();
}
Loading