Closed DanazSdiq closed 1 year ago
I want to make a correction here. The issue has nothing to do with calling services within a .test.ts
files.
The issue:
schools-with-teachers-with-students
works as expected when calling it from Postman. That means the response looks like this:
[
id: 1,
school_name: 'test-school',
teachers: [
{
id: 1,
name: 'test-teacher',
students: [
{
id: 1,
name: 'test-student'
}
]
}
]
]
The response from schools-with-teachers-with-students
does not include teachers
and students
at all when called within other internal services. The response looks something like this:
[
id: 1,
school_name: 'test-school',
]
Is this some hidden behavior of resolveExternal()
? Why is there a difference between the responses?
That is what external resolvers are intended for. To return a different response to an external client vs an internal call. If you want it for both, you'd use schemaHooks.resolveResult:
app.service(path).hooks({
around: {
find: [schemaHooks.resolveResult(schoolTeachersResolver)]
},
before: {
find: [],
get: [disallow('external')],
create: [disallow('external')],
update: [disallow('external')],
patch: [disallow('external')],
remove: [disallow('external')]
}
});
};
Okay this is very useful, thank you very much.
Is there a way @daffl that I can bypass the $select
restriction using resolveResult()
? Currently, when I query the service without passing $select
, I get the following error:
{
"name": "BadRequest",
"message": "Invalid query parameter $select",
"code": 400,
"className": "bad-request",
"data": {
"school_name": "test-school"
},
"errors": {}
}
I have to manually add every single column that I want to be included in the response. I am just wondering if I can bypass this?
That shouldn't happen. What does the query and your setup look like?
Steps to reproduce
I have encountered a weird behavior in trying to write some tests for some of the services that I have. These services use the new Feathers V5 resolvers to join on a few DB tables.
I have another service that builds on
teachers-with-students
service, it looks like this:This works as expected when it comes to calling these services within other services or calling it through Postman like:
Expected behavior
The response body for my service should look like this and (does look like this when called through Postman, within other services, or when using a client library like
fetch
to return results):Actual behavior
The response body within a test looks like this,
teachers
array is completely omitted:Module versions (especially the part that's not working):
NodeJS version: 18
Operating System: MacOS