Hello,
I am trying to setup some local fields for a specific type used in my system (let’s just call it Student
). This Student
type is returned in a number of queries, a students
query that returns Student[]
, a student
query that returns just the single Student
, and other queries such as a course
query that returns and array of students inside of it like this (where students
is and array of Student
):
query Course($id: string!) {
course(id: $id) {
id
subject
name
students {
id
firstName
lastName
fullName @client
}
}
}
And my type policy for Student
is defined as such:
const cache = new InMemoryCache({
typePolicies: {
Student: {
fields: {
fullName: {
read(_, { readField }) {
const firstName = readField<string>('firstName');
const lastName = readField<string>('lastName');
return `${firstName} ${lastName}`;
}
}
},
},
},
});
So the type policy is being respected/used for my student
and students
query, however, when the Student
object is nested inside of another object being queried like that course
query above, the type policy doesn’t seem to be used. My local fields are not part of the Student
object in the response or in cache.
I was wondering if this was expected behavior? Or if maybe there’s something more that has to be done to get this to work? I was also wondering if the type policy should be respected for mutations’ responses as well (imagine an updateCourse
mutation that returns a similar object as the course
query does)?
Thanks