2022-07-29 03:29:28 +02:00
|
|
|
module.exports = ({ createResolvers }) => {
|
2024-01-24 07:27:00 +01:00
|
|
|
// Add images field
|
2022-07-29 03:29:28 +02:00
|
|
|
const resolvers = {
|
2024-01-24 07:27:00 +01:00
|
|
|
BookSection: {
|
2022-07-29 03:29:28 +02:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-01-24 07:28:44 +01:00
|
|
|
|
|
|
|
Example: {
|
|
|
|
screenshot: {
|
|
|
|
type: 'File',
|
|
|
|
resolve: async (source, args, context, info) => {
|
|
|
|
const screenshot = await context.nodeModel.findOne({
|
|
|
|
type: 'File',
|
|
|
|
query: {
|
|
|
|
filter: {
|
|
|
|
relativeDirectory: {
|
|
|
|
eq: source.relativeDirectory,
|
|
|
|
},
|
|
|
|
internal: { mediaType: { regex: '/^(image)/' } },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return screenshot;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2024-10-08 03:07:09 +02:00
|
|
|
|
|
|
|
Exercise: {
|
|
|
|
screenshot: {
|
|
|
|
type: 'File',
|
|
|
|
resolve: async (source, args, context, info) => {
|
|
|
|
const screenshot = await context.nodeModel.findOne({
|
|
|
|
type: 'File',
|
|
|
|
query: {
|
|
|
|
filter: {
|
|
|
|
relativeDirectory: {
|
|
|
|
eq: source.relativeDirectory,
|
|
|
|
},
|
|
|
|
internal: { mediaType: { regex: '/^(image)/' } },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return screenshot;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-07-29 03:29:28 +02:00
|
|
|
};
|
|
|
|
createResolvers(resolvers);
|
|
|
|
};
|