How can I get all fields from query that have been somehow accessed?
I need to know if they have been accessed read or write. It's not always so easy because there could be connect, composite keys in the query and so on. It's not always only the fields in data or where that have been accessed.
2 Replies
Skipping coffee for instant knowledge! Let's brew that AI answer now.
Based on the knowledge sources provided, there doesn't seem to be a direct built-in way in Prisma to get all fields that have been accessed in a query, including read and write operations, especially considering complex scenarios like connections and composite keys.
However, Prisma does offer some features that might help you get closer to what you're looking for:
1. Metrics and Tracing: Prisma provides observability features that can give you insights into query execution. As mentioned in the Prisma and Drizzle comparison, Prisma ORM has built-in metrics and tracing capabilities that can provide per-query information. You could potentially use these features to gain some insight into which fields are being accessed.
2. OpenTelemetry Tracing: The official answer to a related question suggests enabling tracing, which "provides a detailed log of the activity that Prisma Client carries out, at an operation level, including the time taken to execute each query." This might give you more detailed information about field access.
However, it's important to note that these features may not provide the exact level of detail you're looking for, especially regarding write operations or complex scenarios involving connections and composite keys.
For a more comprehensive solution to your specific need, you might need to consider creating a feature request, as suggested in a similar discussion about querying fields in GraphQL. The Prisma team mentioned that certain querying approaches from older versions (like Prisma 1) are not directly supported in newer versions, and suggested creating a feature request for such functionality.
If you need this functionality urgently, you might have to consider implementing a custom solution or middleware that tracks field access in your applica
tion logic, although this would be outside of Prisma's built-in capabilities.
🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly.
In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Hi @Chaos1
Can you please provide more information about your usecase? By default, there is no way to track all fields that have been accessed in a query.