noc-book-2/gatsby/create-resolvers.js
2024-01-24 14:27:00 +08:00

25 lines
671 B
JavaScript

module.exports = ({ createResolvers }) => {
// Add images field
const resolvers = {
BookSection: {
images: {
type: ['File'],
resolve: async (source, args, context, info) => {
const { entries } = await context.nodeModel.findAll({
query: {
filter: {
relativeDirectory: {
eq: `images/${/[^/]*(?=.html)/.exec(source.src)[0]}`,
},
internal: { mediaType: { regex: '/^(image)/' } },
},
},
type: 'File',
});
return entries;
},
},
},
};
createResolvers(resolvers);
};