diff --git a/src/Type_Definitions/Image_Image.js b/src/Type_Definitions/Image_Image.js index c6093be..00b7a78 100644 --- a/src/Type_Definitions/Image_Image.js +++ b/src/Type_Definitions/Image_Image.js @@ -4,6 +4,7 @@ import commonDefs from './Common_Common.js'; const imageDefs = gql` extend type Query { allImages: [Image]! + getImageById(id: String!): Image! } # extend type Mutation { diff --git a/src/resolvers/Query/IMAGE.js b/src/resolvers/Query/IMAGE.js index 8015af5..dbaee94 100644 --- a/src/resolvers/Query/IMAGE.js +++ b/src/resolvers/Query/IMAGE.js @@ -4,6 +4,24 @@ const imageQuery = { allImages: async (parent, args, info) => { return await prisma.image.findMany(); }, + + /** + * @param {*} parent + * @param {{id: string}} args + * @param {*} info + * @returns + */ + getImageById: async (parent, args, info) => { + if (!args.id) { + throw Error('Image Id is not specified'); + } + + return await prisma.image.findUnique({ + where: { + id: args.id, + }, + }); + }, }; export default imageQuery;