Consider the following call:
const userFieldSelection = `
fragment UserSelection on User {
id
email
}
`
const users = await prisma.users().$fragment(userFieldSelection)
Currently the type of users is {} by default. This should be more specific and the call to $fragment should by return the XNode type of the model it was called on.
So, in the above case the type for users should be UserNode[].
Thanks a lot for this suggestion @nikolasburk, however, I don't think it's a good idea to add the model type (e.g. UserNode) as the default generic param since the return value (specified by the fragment string) doesn't necessarily have to match the shape of the model type because of GraphQL field aliases.
Unfortunately, TypeScript doesn't seem to allow a way to "force" the user to provide a generic type param because of it's type inference mechanism but latest if a user tries to access a field (e.g. user.myField) there will be an error message saying Property 'myField' does not exist on type '{}'..
Most helpful comment
Thanks a lot for this suggestion @nikolasburk, however, I don't think it's a good idea to add the model type (e.g.
UserNode) as the default generic param since the return value (specified by the fragment string) doesn't necessarily have to match the shape of the model type because of GraphQL field aliases.Unfortunately, TypeScript doesn't seem to allow a way to "force" the user to provide a generic type param because of it's type inference mechanism but latest if a user tries to access a field (e.g.
user.myField) there will be an error message sayingProperty 'myField' does not exist on type '{}'..