Skip to content

Commit

Permalink
Add getImageById query
Browse files Browse the repository at this point in the history
  • Loading branch information
QuangChanVi committed Dec 6, 2023
1 parent e674ca8 commit 38584cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Type_Definitions/Image_Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions src/resolvers/Query/IMAGE.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 38584cd

Please sign in to comment.