mirror of
https://github.com/aljazceru/landscape-template.git
synced 2025-12-31 04:54:22 +01:00
merge: branch 'graphql-functions' of github.com:bumi/makers.bolt.fun into graphql-functions
This commit is contained in:
24
README.md
24
README.md
@@ -2,6 +2,30 @@
|
||||
|
||||
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
|
||||
|
||||
|
||||
## Database
|
||||
|
||||
Set the `DATABASE_URL` environment variable for your PostgreSQL DB. (e.g. `postgres://bumi@127.0.0.1:5432/bolt_fun_dev`)
|
||||
|
||||
### `prisma studio`
|
||||
|
||||
prisma studio runs an UI for the DB
|
||||
|
||||
### `prisma migrate dev`
|
||||
|
||||
Create a migration from the schema.prisma file
|
||||
|
||||
### `prisma migrate deploy`
|
||||
|
||||
Apply pending migrations to the database
|
||||
|
||||
|
||||
## GraphQL
|
||||
|
||||
GraphQL endpoint is available as netlify function on: `.netlify/functions/graphql`
|
||||
|
||||
Use the Apollo GraphQL Studio to to inspect the GraphQL API: [https://studio.apollographql.com/sandbox/explorer](https://studio.apollographql.com/sandbox/explorer)
|
||||
|
||||
## Available Scripts
|
||||
|
||||
In the project directory, you can run:
|
||||
|
||||
@@ -14,7 +14,16 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
},
|
||||
//Mutation: {
|
||||
// vote: async (_source, args, context) => {},
|
||||
//},
|
||||
Mutation: {
|
||||
vote: async (_source, args, context) => {
|
||||
const project = await context.prisma.project.findUnique({where: { id: args.project_id }});
|
||||
console.log(project)
|
||||
return context.prisma.vote.create({
|
||||
data: {
|
||||
project_id: project.id,
|
||||
amount_in_sat: args.amount_in_sat,
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -16,9 +16,20 @@ module.exports = gql`
|
||||
title: String!
|
||||
}
|
||||
|
||||
type Vote {
|
||||
id: Int!
|
||||
project: Project!
|
||||
amount_in_sat: Int!
|
||||
payment_request: String!
|
||||
paid: Boolean!
|
||||
}
|
||||
|
||||
type Query {
|
||||
allProjects: [Project]!
|
||||
getProject(id: Int!): Project
|
||||
allCategories: [Category]!
|
||||
}
|
||||
type Mutation {
|
||||
vote (project_id: Int!, amount_in_sat: Int!): Vote!
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -45,6 +45,9 @@
|
||||
"storybook": "start-storybook -p 6006 -s public",
|
||||
"build-storybook": "build-storybook -s public"
|
||||
},
|
||||
"prisma": {
|
||||
"seed": "node prisma/seed.js"
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": [
|
||||
"react-app",
|
||||
|
||||
@@ -12,13 +12,29 @@ CREATE TABLE "Project" (
|
||||
"title" TEXT NOT NULL,
|
||||
"description" TEXT NOT NULL,
|
||||
"website" TEXT NOT NULL,
|
||||
"thumbnail_image" TEXT NOT NULL,
|
||||
"cover_image" TEXT NOT NULL,
|
||||
"thumbnail_image" TEXT,
|
||||
"cover_image" TEXT,
|
||||
"category_id" INTEGER NOT NULL,
|
||||
"votes_count" INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
CONSTRAINT "Project_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Vote" (
|
||||
"id" SERIAL NOT NULL,
|
||||
"project_id" INTEGER NOT NULL,
|
||||
"amount_in_sat" INTEGER NOT NULL,
|
||||
"payment_request" TEXT,
|
||||
"payment_hash" TEXT,
|
||||
"preimage" TEXT,
|
||||
"paid" BOOLEAN NOT NULL DEFAULT false,
|
||||
|
||||
CONSTRAINT "Vote_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Project" ADD CONSTRAINT "Project_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "Category"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Vote" ADD CONSTRAINT "Vote_project_id_fkey" FOREIGN KEY ("project_id") REFERENCES "Project"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
@@ -18,9 +18,21 @@ model Project {
|
||||
title String
|
||||
description String
|
||||
website String
|
||||
thumbnail_image String
|
||||
cover_image String
|
||||
thumbnail_image String?
|
||||
cover_image String?
|
||||
category Category @relation(fields: [category_id], references: [id])
|
||||
category_id Int
|
||||
votes_count Int @default(0)
|
||||
Vote Vote[]
|
||||
}
|
||||
|
||||
model Vote {
|
||||
id Int @id @default(autoincrement())
|
||||
project Project @relation(fields: [project_id], references: [id])
|
||||
project_id Int
|
||||
amount_in_sat Int
|
||||
payment_request String?
|
||||
payment_hash String?
|
||||
preimage String?
|
||||
paid Boolean @default(false)
|
||||
}
|
||||
28
prisma/seed.js
Normal file
28
prisma/seed.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const { PrismaClient } = require('@prisma/client')
|
||||
const prisma = new PrismaClient()
|
||||
|
||||
async function main() {
|
||||
const category = await prisma.category.create({
|
||||
data: {
|
||||
title: 'El Salvador',
|
||||
},
|
||||
});
|
||||
|
||||
const project = await prisma.project.create({
|
||||
data: {
|
||||
title: "Captain Morgan",
|
||||
description: "HQ on a VULCANO lake",
|
||||
website: "https://github.com/peakshift",
|
||||
category_id: category.id,
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
main()
|
||||
.catch((e) => {
|
||||
console.error(e)
|
||||
process.exit(1)
|
||||
})
|
||||
.finally(async () => {
|
||||
await prisma.$disconnect()
|
||||
})
|
||||
Reference in New Issue
Block a user