Skip to content

Commit

Permalink
Revert "fix(client): use http2"
Browse files Browse the repository at this point in the history
This reverts commit 1e0910e.
  • Loading branch information
Jolg42 committed May 18, 2020
1 parent ddcc31a commit 47cbf5c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
7 changes: 2 additions & 5 deletions src/packages/client/src/runtime/getPrismaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,14 +628,11 @@ export class PrismaClientFetcher {
}
try {
collectTimestamps && collectTimestamps.record('Pre-engine_request')
const { data, elapsed } = await this.dataloader.request({ document })
const result = await this.dataloader.request({ document })
collectTimestamps && collectTimestamps.record('Post-engine_request')
collectTimestamps && collectTimestamps.record('Pre-unpack')
const unpackResult = this.unpack(document, data, dataPath, rootField)
const unpackResult = this.unpack(document, result, dataPath, rootField)
collectTimestamps && collectTimestamps.record('Post-unpack')
if (process.env.PRISMA_CLIENT_GET_TIME) {
return { data: unpackResult, elapsed }
}
return unpackResult
} catch (e) {
let message = e.message
Expand Down
19 changes: 6 additions & 13 deletions src/packages/engine-core/src/NodeEngine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { convertLog, RustLog, RustError } from './log'
import { spawn, ChildProcessWithoutNullStreams } from 'child_process'
import byline from './byline'
import bent from 'bent'
import { Client } from './client'
import { getLogs } from '@prisma/debug'

const debug = debugLib('engine')
const exists = promisify(fs.exists)
Expand Down Expand Up @@ -86,7 +86,6 @@ export class NodeEngine {
private debug: boolean
private child?: ChildProcessWithoutNullStreams
private clientVersion?: string
private client?: Client
exitCode: number
/**
* exiting is used to tell the .on('exit') hook, if the exit came from our script.
Expand Down Expand Up @@ -610,7 +609,7 @@ ${this.lastErrorLog.fields.file}:${this.lastErrorLog.fields.line}:${this.lastErr
const url = `http://localhost:${this.port}`
this.url = url
// TODO: Re-enable
this.client = new Client(url)
// this.client = new Client(url)
resolve()
} catch (e) {
reject(e)
Expand Down Expand Up @@ -694,25 +693,19 @@ ${this.lastErrorLog.fields.file}:${this.lastErrorLog.fields.line}:${this.lastErr
variables,
}

// this.currentRequestPromise = curly.post(this.url, {
// post: true,
// postFields: JSON.stringify(body),
// httpHeader: ['Content-Type: application/json'],
// })

this.currentRequestPromise = this.client!.request(body)
const post = bent(this.url, 'POST', 'json', 200)
this.currentRequestPromise = post('/', body)

return this.currentRequestPromise
.then(({ data, statusCode, headers }) => {
.then((data) => {
if (data.errors) {
if (data.errors.length === 1) {
throw this.graphQLToJSError(data.errors[0])
}
throw new Error(JSON.stringify(data.errors))
}
const elapsed = parseInt(headers['x-elapsed']) / 1000

return { data, elapsed }
return data
})
.catch((error) => {
debug({ error })
Expand Down
11 changes: 4 additions & 7 deletions src/packages/engine-core/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ import { PrismaQueryEngineError } from './Engine'
export class Client {
private session: http2.ClientHttp2Session
constructor(url: string) {
this.session = http2.connect(url, {
maxSessionMemory: 50,
})
this.session = http2.connect(url, {})

// necessary to disable Node.js' error handling and us handle the error in .on('error') of the session
this.session.on('error', () => {}) // eslint-disable-line @typescript-eslint/no-empty-function
}
close(): void {
this.session.destroy()
}
request(body: any): Promise<{ data: any; headers: any }> {
request(body: any): Promise<unknown> {
return new Promise((resolve, reject) => {
try {
let rejected = false
Expand All @@ -24,9 +22,9 @@ export class Client {
const req = this.session.request({
[http2.constants.HTTP2_HEADER_METHOD]:
http2.constants.HTTP2_METHOD_POST,
[http2.constants.HTTP2_HEADER_PATH]: `/`,
'Content-Type': 'application/json',
'Content-Length': buffer.length,
'Accept-Encoding': '*',
})

req.setEncoding('utf8')
Expand Down Expand Up @@ -79,8 +77,7 @@ export class Client {

req.on('end', () => {
if (data && data.length > 0 && !rejected) {
// console.log(headers)
resolve({ data: JSON.parse(data.join('')), headers })
resolve({ body: JSON.parse(data.join('')), headers })
}
})
} catch (e) {
Expand Down

0 comments on commit 47cbf5c

Please sign in to comment.