Skip to content
Myr

fix(client): `continue` if query value is `undefined` (#1368)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(client): `continue` if query value is `undefined` * denoify

authored by Yusuke Wada · committed by GitHub · parent 2685a9b · Browse files · 3 files+12 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+12 added−9 removed

  • tests:+10 added−7 removed
  • other:+2 added−2 removed

3 files+12 added−9 removed

modified:deno_dist/client/client.ts+1 added-1 removed
modified:src/client/client.test.ts+10 added-7 removed
126 unmodified lines
127 const route = app128 .get(129 '/search',130 validator('query', () => {131 return {} as { q: string; tag: string[] }131 return {} as { q: string; tag: string[]; filter: string }132 }),133 (c) => {134 return c.jsonT({135 entries: [136 {137 title: 'Foo',138 },139 ],135 q: 'fake',136 tag: ['fake'],137 filter: 'fake',138 })139 }140 )141 .get(
25 unmodified lines
167 rest.get('http://localhost/api/search', (req, res, ctx) => {168 const url = new URL(req.url)169 const query = url.searchParams.get('q')170 const tag = url.searchParams.getAll('tag')171 const filter = url.searchParams.get('filter')172 return res(173 ctx.status(200),174 ctx.json({175 q: query,177 tag: tag,176 tag,177 filter,178 })179 )180 }),181 rest.get('http://localhost/api/posts', (req, res, ctx) => {
26 unmodified lines
208 const res = await client.search.$get({209 query: {210 q: 'foobar',211 tag: ['a', 'b'],212 // @ts-expect-error213 filter: undefined,214 },215 })216217 expect(res.status).toBe(200)218 expect(await res.json()).toEqual({219 q: 'foobar',220 tag: ['a', 'b'],221 filter: null,222 })223 })224225 it('Should get 200 response - queries', async () => {
225 unmodified lines
modified:src/client/client.ts+1 added-1 removed
40 unmodified lines
41 if (args) {42 if (args.query) {43 for (const [k, v] of Object.entries(args.query)) {44 if (v === undefined) {45 return45 continue46 }4748 this.queryParams ||= new URLSearchParams()49 if (Array.isArray(v)) {
89 unmodified lines