-
Notifications
You must be signed in to change notification settings - Fork 9
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
Fluent API returns incorrect object structure with read replica #12
Comments
This seems to be a deeper problem in client extensions, since I've encountered this when running my own client extensions. |
This issue seems to be specific to this extension needing to reconstruct a method call to the replica: extension-read-replicas/src/extension.ts Lines 72 to 76 in 3c1a712
The fluent API gets translated into Within |
I am having the same exact issue. This extension cannot be used on projects using the fluent API. |
@SevInf do you know when this might get fixed? 🙂 |
Sorry, can not provide ETA at the moment. Query extensions seem to have a problem with Fluent API in general and we probably should fix it in Prisma Client rather than work around in extension. |
Do we have a higher level issue for this @SevInf that we can link to? |
Tried adding a replica and ran into this same issue. |
Are there any updates to this? This extension is still completely useable for applications that use the fluent API. |
I'd love to see this fixed too. This is such a great extension, but we can't use it until it supports the fluent API. |
We are using the fluent API and really want to see this land as well. FWIW we slightly modified the async $allOperations({
// @ts-expect-error __internalParams does not appear on the type as it's an internal property
__internalParams: { dataPath, transaction },
args,
model,
operation,
query,
}) {
if (transaction) return query(args);
if (readOperations.includes(operation)) {
const replica = replicaManager.pickReplica() as unknown as {
[key: string]: {
[key: string]: (args: unknown) => Promise<unknown>;
};
};
if (
typeof replica === "object" &&
replica !== null &&
model &&
model in replica
) {
const modelMethod = replica[model];
if (modelMethod && operation in modelMethod) {
const readMethod = modelMethod[operation];
if (readMethod) {
const res = (await readMethod(args)) as {
[key: string]: unknown;
};
// This is a workaround for the Fluent API.
// This references the internal dataPath to access the correct
// nested property of the result.
const path = dataPath as string[];
if (path && path.length > 1) {
const p = path[1];
if (p && p in res) return res[p];
}
return res;
}
}
}
}
return query(args);
} |
I put up a PR trying to productionize @jadenlemmon, though of course I'm not able to eliminate the fundamental jankiness of using (more) internal APIs: #36 |
Has anyone found a workaround for this? |
When using Prisma's Fluent API with a read replica, the returned object does not adhere to the expected structure.
Repro: read-replicas-demo
Current Behavior:
Using the primary database, the following code:
returns:
However, when using a read replica, this code:
returns a nested object:
Expected Behavior
Using a read replica should also return:
The text was updated successfully, but these errors were encountered: