- Node app to display data from a PostgreSQL database using Apollo-Server & GraphQL.
- Note: to open web links in a new window use: ctrl+click on link
- PostgreSQL used as the database with Prisma to access it. PostgreSQL installed on Windows 10 Home. It was not possible to use MongoDB Atlas.
- Prisma Client used: auto-generated & type-safe query builder. Prisma CRUD operations are asynchronous.
- Node.js v16 JavaScript runtime built on Chrome's V8 JavaScript engine.
- Apollo Server v2 to connect a GraphQL schema to an HTTP server in Node. js.
- GraphQL v2 - latest is version 3 but that does not include the GraphQL playground by default
- Prisma v3 database toolkit for PostgreSQL
- Prisma Studio v3 database GUI. Only opens in inPrivate Chrome web browser
- WebSocket subscriptions for realtime notifications
- Apollo external PubSub Engine using the AsyncIterator interface
- BCrypt.js v2 password-hashing function
- jsonwebtoken v8: a compact, URL-safe means of representing claims to be transferred between two parties.
- Install dependencies using
npm i
- Add database URL to
.env
- seeexample.env
. Database is specified inschema.prisma
- Run
node src/index.js
to start app - After changes to prisma run
npx prisma migrate dev --name "very brief summary"
- To apply the changes and update your Prisma Client API run
npx prisma generate
- n/a
/resolvers/Mutation.js
nested write function to write relational data to database
async function post(parent, args, context, info) {
const { userId } = context;
return await context.prisma.link.create({
data: {
url: args.url,
description: args.description,
title: args.title,
postedBy: {
connect: {
id: userId,
},
},
},
});
}
- GraphQL: provides a complete and understandable description of the API data. Clients can ask for exactly what they need and nothing more, saving cost on mobile data plans etc. Easier to evolve APIs over time. Enables powerful developer tools
- Status: Working
- To-Do: Nothing
- N/A
- Repo created by ABateman, email: gomezbateman@yahoo.com