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

chore(client): [DPGA] implement --data-proxy #13484

Closed
wants to merge 28 commits into from
Closed

Conversation

millsp
Copy link
Member

@millsp millsp commented May 25, 2022

This PR replaces the PRISMA_CLIENT_ENGINE_TYPE=dataproxy mechanism in favor of --data-proxy via the cli.

Next #13512

https://github.com/orgs/prisma/projects/70#card-82299232

@millsp millsp changed the title fix(lint): failing on sub-projects and simplify it chore(client): Data Proxy GA May 25, 2022
@millsp millsp added this to the 3.15.0 milestone May 25, 2022
@millsp millsp self-assigned this May 25, 2022
@SevInf
Copy link
Contributor

SevInf commented May 25, 2022

Warning: potentially stupid question ahead.
Should we do something in case when engineType defined explicitly and --data-proxy flag is used? I am not sure what hypothetical user wants to achieve with this combination, but engineType would be ignored in this case, so maybe it worth a warning?

@millsp
Copy link
Member Author

millsp commented May 25, 2022

It's a good question, so I'll try to answer with what I think is my best opinion.

If we stick to the fact that --data-proxy means "I can only use Client with the Data Proxy from now",
as I understand it, we don't need to emit a warning since the intent of the user is clearly expressed.
If --data-proxy is enabled, they will get an error in any case where the datasource is not prisma://.
And alternatively, they will also get an error if they pass a prisma:// url and --data-proxy isn't set.
Also, engineType is a user-facing implementation detail meant to be an escape hatch (not a feature).

@millsp millsp changed the title chore(client): Data Proxy GA chore(client): [DPGA] implement --data-proxy May 26, 2022
@@ -5,7 +5,6 @@ datasource db {

generator client {
provider = "prisma-client-js"
engineType = "dataproxy"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a valid entry anymore.

@@ -11,7 +11,7 @@ function normalizePaths(snapshot: string): string {

describe('library', () => {
it('generates annotations for a schema and a single engine', () => {
const annotations = buildNFTAnnotations(ClientEngineType.Library, ['debian-openssl-1.1.x'], 'out')
const annotations = buildNFTAnnotations(false, ClientEngineType.Library, ['debian-openssl-1.1.x'], 'out')
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataProxy = false

@@ -84,16 +86,15 @@ describe('binary', () => {
describe('dataproxy', () => {
it('generates no annotations', () => {
const annotations = buildNFTAnnotations(
ClientEngineType.DataProxy,
true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataProxy = true

@@ -5,11 +5,6 @@ import path from 'path'

import { generateTestClient } from '../../../../utils/getTestClient'

if (getClientEngineType() === ClientEngineType.DataProxy) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed.

@@ -86,15 +88,16 @@ export class TSClient implements Generatable {
engineVersion: this.options.engineVersion,
datasourceNames: datasources.map((d) => d.name),
activeProvider: this.options.activeProvider,
dataProxy: this.options.dataProxy,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataProxy is now stored in the generated config instead of being in the generator config block (via schema).

@@ -62,6 +63,7 @@ export class TSClient implements Generatable {
runtimeDir,
runtimeName,
datasources,
dataProxy,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed by the generator.

${buildWarnEnvConflicts(engineType, runtimeDir, runtimeName)}
${buildInlineDatasource(dataProxy, datasources)}
${await buildInlineSchema(dataProxy, schemaPath)}
${buildInlineEnv(dataProxy, datasources, envPaths)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be removed in the followup PR.

}

// get relative output dir for it to be preserved even after bundling, or
// being moved around as long as we keep the same project dir structure.
const relativeOutdir = path.relative(process.cwd(), outputDir)

const code = `${commonCodeJS({ ...this.options, browser: false })}
${buildRequirePath(engineType)}
${buildDirname(engineType, relativeOutdir, runtimeDir)}
${buildRequirePath(dataProxy)}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use the engine type in most cases anymore as that was used to do the data proxy distinction at generation time.

@@ -57,7 +58,6 @@ export interface BuildClientResult {

// eslint-disable-next-line @typescript-eslint/require-await
export async function buildClient({
datamodel,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not used.

@@ -48,6 +48,7 @@ export interface GenerateClientOptions {
engineVersion: string
clientVersion: string
activeProvider: string
dataProxy: boolean
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed to generateClient via the generator.

@@ -238,7 +242,8 @@ export async function generateClient({
}\` in the \`binaryPaths\` object.`,
)
}
if (transpile) {

if (transpile === true && dataProxy === false) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't copy the query engine files if the data proxy is in use.

@@ -51,6 +51,7 @@ if (process.argv[1] === __filename) {
clientVersion,
transpile: true,
activeProvider: options.datasources[0]?.activeProvider,
dataProxy: options.dataProxy,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passed by the cli.

@@ -449,7 +458,9 @@ export function getPrismaClient(config: GetPrismaClientConfig) {
return 'PrismaClient'
}
private getEngine(): Engine {
if (this._clientEngineType === ClientEngineType.Library) {
if (this._dataProxy === true) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataProxy = true is an override of the other engines, as explicitly asked via --data-proxy

@@ -36,7 +36,7 @@ function getAllTestSuiteTypeChecks(fileNames: string[]) {

describe('typescript', () => {
const suitePaths = glob.sync('./**/.generated/**/*.ts', {
ignore: ['./**/.generated/**/*.d.ts', './**/.generated/**/_schema.ts'],
ignore: ['./**/.generated/**/*.d.ts', './**/.generated/**/_*.ts'],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change.

@@ -1,3 +1,3 @@
import { build } from '../../../helpers/compile/build'

void build([{ name: 'default' }])
void build([{ name: 'debug' }])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change.

@@ -237,7 +234,7 @@ export class DataProxyEngine extends Engine {
const { protocol, host, searchParams } = url

if (protocol !== 'prisma:') {
throw new InvalidDatasourceError('Datasource URL should use prisma:// protocol. If you are not using the Data Proxy, remove the `dataProxy` from the `previewFeatures` in your schema and ensure that `PRISMA_CLIENT_ENGINE_TYPE` environment variable is not set to `dataproxy`.', {
throw new InvalidDatasourceError('Datasource URL should use prisma:// protocol when --data-proxy is used', {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: use "must" instead of "should"

},
RequestInit
>
// our implementation handles less than the real fetch
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of the removal of ambient types from webworkers.

@@ -155,6 +155,7 @@ export class Migrate {
printDownloadProgress: true,
version: enginesVersion,
cliVersion: packageJson.version,
dataProxy: false,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't allow --data-proxy on prisma migrate as they are not currently compatible.

provider = \\"prisma-client-js\\"
previewFeatures = [\\"dataProxy\\"]
}
interactiveTransactions preview feature is not yet available with --data-proxy.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: re-enable this test.

@@ -3,7 +3,6 @@ import type { GeneratorConfig } from '@prisma/generator-helper'
export enum ClientEngineType {
Library = 'library',
Binary = 'binary',
DataProxy = 'dataproxy',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not allowed here anymore.

}

function checkProxyFeatureFlag(config: ConfigMetaFormat) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed anymore.

}

function checkProxyFeatureFlag(config: ConfigMetaFormat) {
function checkForbiddenItxWithDataProxyFlag(config: ConfigMetaFormat, options: GetGeneratorOptions) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure that itx cannot be used with --data-proxy.

@millsp
Copy link
Member Author

millsp commented May 30, 2022

Replaced by #13561

@millsp millsp closed this May 30, 2022
@Jolg42 Jolg42 deleted the chore/data-proxy-ga branch July 5, 2022 07:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants