validateAndTransformQuery "defaults" field #10817
-
Hello! I am facing a problem when applying query-parameter validation. I am using the standard validation scheme: export default defineMiddlewares({
routes: [
{
matcher: "/admin/site-contents",
method: "GET",
middlewares: [
validateAndTransformQuery(siteContentsQuerySchema, {
defaults: ["*"],
isList: true,
}),
],
},
],
}); I want all fields to be displayed, so I apply
server error:
route code: export const GET = async (
{ scope, remoteQueryConfig }: MedusaRequest,
res: MedusaResponse
) => {
const query = scope.resolve(ContainerRegistrationKeys.QUERY);
console.log(remoteQueryConfig.fields);
const { data: site_contents, metadata: { count, take, skip } = {} } =
await query.graph<string>({
entity: SITE_CONTENT_ENTITY_NAME,
...remoteQueryConfig,
});
res.json({
site_contents,
count,
limit: take,
offset: skip,
});
};
Entity schema: export const SiteContent = model.define(SITE_CONTENT_ENTITY_NAME, {
id: model.id().primaryKey(),
name: model.text(),
page_key: model.enum([...PAGE_KEYS]),
is_active: model.boolean().default(false),
config: model.json(),
}); |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@qFlensT, In your case, this would look something along the lines of:
That said, it might make sense to support this query config–we'll discuss this internally. |
Beta Was this translation helpful? Give feedback.
@qFlensT,
*
is not a valid property to specify infields
on the root resource. You can use it to pick all fields on relations, but for the root resource, you need to explicitly specify the fields to include.In your case, this would look something along the lines of:
That said, it might make sense to support this query config–we'll discuss this internally.