mirror of
https://github.com/aljazceru/landscape-template.git
synced 2025-12-27 19:24:18 +01:00
fix: change prisma init place, make category icon nullable
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const { ApolloServer } = require("apollo-server-lambda");
|
||||
// const resolvers = require("./resolvers/resolvers");
|
||||
// const typeDefs = require("./schema");
|
||||
// const { prisma } = require('./prisma')
|
||||
const { prisma } = require('./prisma')
|
||||
const schema = require('./schema')
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ const server = new ApolloServer({
|
||||
|
||||
context: () => {
|
||||
return {
|
||||
// prisma,
|
||||
prisma,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,26 +3,26 @@ const {
|
||||
objectType,
|
||||
extendType,
|
||||
nonNull,
|
||||
} = require('nexus')
|
||||
const { prisma } = require('../prisma')
|
||||
} = require('nexus');
|
||||
|
||||
|
||||
const Category = objectType({
|
||||
name: 'Category',
|
||||
definition(t) {
|
||||
t.nonNull.int('id');
|
||||
t.nonNull.string('title');
|
||||
t.nonNull.string('cover_image');
|
||||
t.nonNull.string('icon');
|
||||
t.string('cover_image');
|
||||
t.string('icon');
|
||||
|
||||
|
||||
t.nonNull.int('votes_sum', {
|
||||
async resolve(parent) {
|
||||
async resolve(parent, _, { prisma }) {
|
||||
const projects = await prisma.category.findUnique({ where: { id: parent.id } }).project();
|
||||
return projects.reduce((total, project) => total + project.votes_count, 0);
|
||||
}
|
||||
});
|
||||
t.nonNull.int('apps_count', {
|
||||
async resolve(parent) {
|
||||
async resolve(parent, _, { prisma }) {
|
||||
const projects = await prisma.category.findUnique({ where: { id: parent.id } }).project();
|
||||
return projects.length;
|
||||
|
||||
@@ -31,7 +31,7 @@ const Category = objectType({
|
||||
|
||||
t.nonNull.list.nonNull.field('project', {
|
||||
type: "Project",
|
||||
resolve: (parent) => {
|
||||
resolve: (parent, _, { prisma }) => {
|
||||
return parent.project ?? prisma.category.findUnique({
|
||||
where: { id: parent.id }
|
||||
}).project()
|
||||
@@ -45,7 +45,7 @@ const allCategoriesQuery = extendType({
|
||||
definition(t) {
|
||||
t.nonNull.list.nonNull.field('allCategories', {
|
||||
type: "Category",
|
||||
resolve: async () => {
|
||||
resolve: async (parent, args, { prisma }) => {
|
||||
const categories = await prisma.category.findMany({
|
||||
include: {
|
||||
_count: {
|
||||
@@ -70,7 +70,7 @@ const getCategory = extendType({
|
||||
args: {
|
||||
id: nonNull(intArg())
|
||||
},
|
||||
resolve(parent, { id }) {
|
||||
resolve(parent, { id }, { prisma }) {
|
||||
return prisma.category.findUnique({
|
||||
where: { id }
|
||||
})
|
||||
|
||||
@@ -6,7 +6,6 @@ const {
|
||||
nonNull,
|
||||
} = require('nexus')
|
||||
|
||||
const { prisma } = require('../prisma');
|
||||
const { paginationArgs, getLnurlDetails, lightningAddressToLnurl } = require('./helpers');
|
||||
|
||||
|
||||
@@ -26,21 +25,21 @@ const Project = objectType({
|
||||
|
||||
t.nonNull.field('category', {
|
||||
type: "Category",
|
||||
resolve: (parent) => {
|
||||
resolve: (parent, args, { prisma }) => {
|
||||
return prisma.project.findUnique({ where: { id: parent.id } }).category();
|
||||
}
|
||||
});
|
||||
|
||||
t.nonNull.list.nonNull.field('awards', {
|
||||
type: "Award",
|
||||
resolve: (parent) => {
|
||||
resolve: (parent, args, { prisma }) => {
|
||||
return prisma.project.findUnique({ where: { id: parent.id } }).awards();
|
||||
}
|
||||
});
|
||||
|
||||
t.nonNull.list.nonNull.field('tags', {
|
||||
type: "Tag",
|
||||
resolve: (parent) => {
|
||||
resolve: (parent, args, { prisma }) => {
|
||||
return prisma.project.findUnique({ where: { id: parent.id } }).tags();
|
||||
}
|
||||
})
|
||||
@@ -57,7 +56,7 @@ const Award = objectType({
|
||||
t.nonNull.string('url');
|
||||
t.nonNull.field('project', {
|
||||
type: "Project",
|
||||
resolve: (parent) => {
|
||||
resolve: (parent, args, { prisma }) => {
|
||||
return prisma.award.findUnique({ where: { id: parent.id } }).project();
|
||||
}
|
||||
})
|
||||
@@ -71,7 +70,7 @@ const Tag = objectType({
|
||||
t.nonNull.string('title');
|
||||
t.nonNull.list.nonNull.field('project', {
|
||||
type: "Project",
|
||||
resolve: (parent) => {
|
||||
resolve: (parent, args, { prisma }) => {
|
||||
return prisma.tag.findUnique({ where: { id: parent.id } }).project();
|
||||
}
|
||||
})
|
||||
@@ -87,7 +86,7 @@ const getProject = extendType({
|
||||
args: {
|
||||
id: nonNull(intArg())
|
||||
},
|
||||
resolve(_, { id }) {
|
||||
resolve(_, { id }, { prisma }) {
|
||||
return prisma.project.findUnique({
|
||||
where: { id }
|
||||
})
|
||||
@@ -102,7 +101,7 @@ const allProjects = extendType({
|
||||
t.nonNull.list.nonNull.field('allProjects', {
|
||||
type: "Project",
|
||||
args: paginationArgs({ take: 50 }),
|
||||
resolve(_, { take, skip }) {
|
||||
resolve(_, { take, skip }, { prisma }) {
|
||||
return prisma.project.findMany({
|
||||
orderBy: { votes_count: "desc" },
|
||||
skip,
|
||||
@@ -119,7 +118,7 @@ const newProjects = extendType({
|
||||
t.nonNull.list.nonNull.field('newProjects', {
|
||||
type: "Project",
|
||||
args: paginationArgs({ take: 50 }),
|
||||
resolve(_, args) {
|
||||
resolve(_, args, { prisma }) {
|
||||
const take = args.take || 50;
|
||||
const skip = args.skip || 0;
|
||||
return prisma.project.findMany({
|
||||
@@ -139,7 +138,7 @@ const hottestProjects = extendType({
|
||||
t.nonNull.list.nonNull.field('hottestProjects', {
|
||||
type: "Project",
|
||||
args: paginationArgs({ take: 50 }),
|
||||
async resolve(_, { take, skip }) {
|
||||
async resolve(_, { take, skip }, { prisma }) {
|
||||
return prisma.project.findMany({
|
||||
orderBy: { votes_count: "desc" },
|
||||
skip,
|
||||
@@ -160,7 +159,7 @@ const searchProjects = extendType({
|
||||
...paginationArgs({ take: 50 }),
|
||||
search: nonNull(stringArg())
|
||||
},
|
||||
async resolve(_, { take, skip, search }) {
|
||||
async resolve(_, { take, skip, search }, { prisma }) {
|
||||
return prisma.project.findMany({
|
||||
where: {
|
||||
OR: [{
|
||||
@@ -193,7 +192,7 @@ const projectsByCategory = extendType({
|
||||
...paginationArgs(),
|
||||
category_id: nonNull(intArg())
|
||||
},
|
||||
async resolve(_, { take, skip, category_id }) {
|
||||
async resolve(_, { take, skip, category_id }, { prisma }) {
|
||||
return prisma.project.findMany({
|
||||
where: { category_id },
|
||||
orderBy: { votes_count: "desc" },
|
||||
@@ -212,7 +211,7 @@ const getLnurlDetailsForProject = extendType({
|
||||
t.nonNull.field('getLnurlDetailsForProject', {
|
||||
type: "LnurlDetails",
|
||||
args: { project_id: nonNull(intArg()) },
|
||||
async resolve(_, args) {
|
||||
async resolve(_, args, { prisma }) {
|
||||
const project = await prisma.project.findUnique({
|
||||
where: {
|
||||
id: args.project_id,
|
||||
|
||||
@@ -5,7 +5,6 @@ const {
|
||||
nonNull,
|
||||
stringArg,
|
||||
} = require('nexus')
|
||||
const { prisma } = require('../prisma')
|
||||
const { parsePaymentRequest } = require('invoices');
|
||||
const { getPaymetRequestForProject, hexToUint8Array } = require('./helpers');
|
||||
const { createHash } = require('crypto');
|
||||
@@ -25,7 +24,7 @@ const Vote = objectType({
|
||||
|
||||
t.nonNull.field('project', {
|
||||
type: "Project",
|
||||
resolve: (parent) => {
|
||||
resolve: (parent, args, { prisma }) => {
|
||||
return parent.project ?? prisma.vote.findUnique({
|
||||
where: { id: parent.id }
|
||||
}).project()
|
||||
@@ -54,7 +53,7 @@ const voteMutation = extendType({
|
||||
project_id: nonNull(intArg()),
|
||||
amount_in_sat: nonNull(intArg())
|
||||
},
|
||||
resolve: async (_, args) => {
|
||||
resolve: async (_, args, { prisma }) => {
|
||||
const project = await prisma.project.findUnique({
|
||||
where: { id: args.project_id },
|
||||
});
|
||||
@@ -86,7 +85,7 @@ const confirmVoteMutation = extendType({
|
||||
payment_request: nonNull(stringArg()),
|
||||
preimage: nonNull(stringArg())
|
||||
},
|
||||
resolve: async (_, args) => {
|
||||
resolve: async (_, args, { prisma }) => {
|
||||
const paymentHash = createHash("sha256")
|
||||
.update(hexToUint8Array(args.preimage))
|
||||
.digest("hex");
|
||||
|
||||
Reference in New Issue
Block a user