I'm using Apollo Server and Prisma to query my graphQL server:
I have this resolver:
const resolvers = {
Query: {
sessions: async () => {
const allSessions = await prisma.session.findMany()
console.log(allSessions)
return allSessions
},
},
};
Which is called in my app component:
public ngOnInit(): void {
this.apollo.query<SessionArray>({
query: GET_SESSIONS
}).subscribe(({ data }) => {
console.log(data)
this.sessions = data.sessions
}
)
}
This is the gql:
const GET_SESSIONS = gql`
query GetSession {
sessions {
id
}
}
`
And the TypeScript types:
type SessionArray = {
sessions: Array<Session>
}
type Session = {
id: number;
}
My problem here is the type annotation of the query in the ngOnInit
. I now have a type that just says the server returns an array with Sessions.
Is there any way to improve this type annotation?