Skip to content

Commit

Permalink
Fix runaway mutability bug in httpMethod (#3963)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Bayer <[email protected]>
Closes #3962
  • Loading branch information
tmcw authored Nov 14, 2022
1 parent aaed9ca commit c0a3b1e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-dots-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@blitzjs/rpc": minor
---

Fix mutability bug in RPC configuration
30 changes: 30 additions & 0 deletions packages/blitz-rpc/src/parse-rpc-config.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {describe, expect, it} from "vitest"
import {getResolverConfig} from "./parse-rpc-config"

describe("getResolverConfig", () => {
it("base case: no configuration", async () => {
const result = getResolverConfig("")
expect(result).toHaveProperty("httpMethod", "POST")
})

it("customized to get", async () => {
const result = getResolverConfig(`
export const config = {
httpMethod: 'GET'
}
`)
expect(result).toHaveProperty("httpMethod", "GET")
})

it("evaluation is hermetic", async () => {
expect(
getResolverConfig(`
export const config = {
httpMethod: 'GET'
}
`),
).toHaveProperty("httpMethod", "GET")

expect(getResolverConfig(``)).toHaveProperty("httpMethod", "POST")
})
})
8 changes: 3 additions & 5 deletions packages/blitz-rpc/src/parse-rpc-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ import {ResolverConfig} from "blitz"

type _ResolverType = "GET" | "POST"

const defaultResolverConfig: ResolverConfig = {
httpMethod: "POST",
}

export function getResolverConfig(content: string): ResolverConfig {
const resolverConfig = defaultResolverConfig
const resolverConfig: ResolverConfig = {
httpMethod: "POST",
}
const resolver = parseSync(content, {
syntax: "typescript",
target: "es2020",
Expand Down

0 comments on commit c0a3b1e

Please sign in to comment.