@ethlete/query 5.31.1 → 5.31.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @ethlete/query
2
2
 
3
+ ## 5.31.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a26a8c6`](https://github.com/ethlete-io/ethdk/commit/a26a8c6c374fd60152e7bd430500d2b1777f4be8) Thanks [@TomTomB](https://github.com/TomTomB)! - Fix gql query variables not getting parsed as json when transported via query params
8
+
3
9
  ## 5.31.1
4
10
 
5
11
  ### Patch Changes
@@ -122,7 +122,19 @@ const buildQueryString = (params, config) => {
122
122
  const ignoredValuesFns = config?.ignoredValuesFns ?? [isNaN$1, isEmptyString];
123
123
  const queryParams = [];
124
124
  function processValue(key, value) {
125
- if (Array.isArray(value)) {
125
+ if (config?.useJsonStringify) {
126
+ if (ignoredValues.includes(value)) {
127
+ return false;
128
+ }
129
+ if (ignoredValuesFns.some((fn) => fn(value))) {
130
+ return false;
131
+ }
132
+ const encodedKey = encodeURIComponent(key);
133
+ const encodedValue = encodeURIComponent(JSON.stringify(value));
134
+ queryParams.push(`${encodedKey}=${encodedValue}`);
135
+ return true;
136
+ }
137
+ else if (Array.isArray(value)) {
126
138
  let currentFilteredIndex = 0;
127
139
  for (const arrayValue of value) {
128
140
  const nestedKey = writeArrayIndexes ? `${key}[${currentFilteredIndex}]` : `${key}[]`;
@@ -704,12 +716,19 @@ class QueryCreator {
704
716
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
705
717
  // @ts-ignore
706
718
  this.prepare = (args) => {
719
+ const shouldUseJsonStringifyForQs = isGqlQueryConfig(this._queryConfig) &&
720
+ (this._queryConfig.transferVia === 'GET' ||
721
+ (this._client.config.request?.gql?.transferVia === 'GET' && !this._queryConfig.transferVia));
722
+ const originalQueryParams = this._client.config.request?.queryParams;
723
+ const queryParamConfig = originalQueryParams
724
+ ? { ...originalQueryParams, useJsonStringify: shouldUseJsonStringifyForQs }
725
+ : undefined;
707
726
  const route = buildRoute({
708
727
  base: this._client.config.baseRoute,
709
728
  route: this._queryConfig.route,
710
729
  pathParams: args?.pathParams,
711
730
  queryParams: computeQueryQueryParams({ config: this._queryConfig, client: this._client, args }),
712
- queryParamConfig: this._client.config.request?.queryParams,
731
+ queryParamConfig,
713
732
  });
714
733
  const cacheKey = (args?.config?.queryStoreCacheKey ?? '') + buildQueryCacheKey$1(route, args);
715
734
  if (shouldCacheQuery$1(this._queryConfig.method) && !args?.config?.skipQueryStore) {
@@ -4249,7 +4268,9 @@ const createQueryRepository = (config) => {
4249
4268
  route: options.route,
4250
4269
  pathParams: args?.pathParams,
4251
4270
  queryParams: args?.queryParams,
4252
- queryParamConfig: config.queryString,
4271
+ queryParamConfig: options.internalRunQueryOptions?.forceJsonStringifyInQueryParams
4272
+ ? { useJsonStringify: true }
4273
+ : config.queryString,
4253
4274
  });
4254
4275
  const key = shouldCache &&
4255
4276
  buildQueryCacheKey(`${options.key ? options.key + '_' : ''}${route}`, {
@@ -4576,6 +4597,7 @@ const createGqlExecuteFn = (executeOptions) => {
4576
4597
  options,
4577
4598
  internalOptions: {
4578
4599
  useQueryRepositoryCache: executeOptions.creatorInternals.method === 'QUERY',
4600
+ forceJsonStringifyInQueryParams: executeOptions.creatorInternals.method === 'QUERY',
4579
4601
  },
4580
4602
  transformResponse: (originalResponse) => {
4581
4603
  if (originalResponse && 'data' in originalResponse) {