Is it possible to use nested queries with TypeScri...
# orm-help
f
Is it possible to use nested queries with TypeScript and prisma-client-lib? Previously with prisma-binding, it was possible to pass the info variable to the binding, but the prisma-client-lib lacks this capability. This blog https://medium.com/@lukehamilton/nested-relations-in-prisma-971e060a16ab helps me so far, I only have to extract the fragment from the info parameter. Are there already solutions?
If somebody is interested, I solved this problem with this quickfix. // This function constructs the user query from the info parameter. // TODO(till): This is a quick fix, wait for the Prisma client to support nested queries on its own. export function infoToUserQuery(info, current: string = ‘’): string { if (current === ‘’) { info = info.fieldNodes[0].selectionSet.selections; } current += ‘{ ‘; for (const selection of info) { current += selection.name.value + ’ ‘; if (selection.selectionSet) { current = infoToUserQuery(selection.selectionSet.selections, current); } } current += ‘}’; return current; }
@Harshit Thank you very much for this great solution. There is a better way to do this using type resolvers. See: https://www.prisma.io/tutorials/a-guide-to-common-resolver-patterns-ct08/#scenario:-implementing-relations-with-prisma-client