Skip to content

Commit

Permalink
add new prisma model
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkie committed Oct 5, 2020
1 parent c8f36cf commit 2ebb56d
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 65 deletions.
73 changes: 73 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
"prisma": "prisma"
},
"dependencies": {
"@prisma/client": "^2.8.0",
"apollo-server": "^2.18.2",
"bcryptjs": "^2.4.3",
"graphql-yoga": "^1.7.0",
"jsonwebtoken": "^8.2.0",
"prisma-client-lib": "^1.31.0"
"jsonwebtoken": "^8.2.0"
},
"devDependencies": {
"prisma": "^1.31.0"
"@prisma/cli": "^2.8.0"
}
}
23 changes: 0 additions & 23 deletions server/prisma/datamodel.prisma

This file was deleted.

Empty file added server/prisma/dev.db
Empty file.
15 changes: 0 additions & 15 deletions server/prisma/prisma.yml

This file was deleted.

38 changes: 38 additions & 0 deletions server/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

datasource db {
provider = "sqlite"
url = "file:./dev.db"
}

generator client {
provider = "prisma-client-js"
}

model Link {
id String @id @default(cuid())
description String
url String
createdAt DateTime @default(now())
postedBy User @relation(fields: [userId], references: [id])
votes Vote[]
userId String
}

model User {
id String @id @default(cuid())
name String
email String
password String
links Link[]
votes Vote[]
}

model Vote {
id String @id @default(cuid())
link Link @relation(fields: [linkId], references: [id])
user User @relation(fields: [userId], references: [id])
linkId String
userId String
}
38 changes: 15 additions & 23 deletions server/src/index.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,19 @@
const { GraphQLServer } = require('graphql-yoga')
const { prisma } = require('./generated/prisma-client')
const Query = require('./resolvers/Query')
const Mutation = require('./resolvers/Mutation')
const Subscription = require('./resolvers/Subscription')
const User = require('./resolvers/User')
const Link = require('./resolvers/Link')
const Vote = require('./resolvers/Vote')
import { ApolloServer } from 'apollo-server';
import { PrismaClient } from '@prisma/client';
import * as resolvers from './resolvers';

const resolvers = {
Query,
Mutation,
Subscription,
User,
Link,
Vote,
}
const prisma = new PrismaClient();

const server = new GraphQLServer({
const server = new ApolloServer({
typeDefs: './src/schema.graphql',
resolvers,
context: request => ({
...request,
prisma,
}),
})
server.start(() => console.log(`Server is running on http://localhost:4000`))
context: () => ({
prisma
})
});

server.listen().then(({ port }) => {
console.log(
`Server listening on http://localhost:${port}`
);
});
6 changes: 6 additions & 0 deletions server/src/resolvers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export * as Link from './Link';
export * as Mutation from './Mutation';
export * as Query from './Query';
export * as Subscription from './Subscription';
export * as User from './User';
export * as Vote from './Vote';

0 comments on commit 2ebb56d

Please sign in to comment.