graphql install
npm install graphql --save
postgresql nodejs
//connect to postgres database in node
const Pool = require('pg').Pool;
const pool = new Pool({
user: '',
host: 'localhost',
database: '',
password: '',
port:5432,
})
//query example
app.get('/users',async(req,res)=>{
try{
let resp=await pool.query('SELECT * FROM users');
}catch(err){
res.status(200).send(resp.rows);
}
})
postgresql nodejs
const { Client } = require('pg')const client = new Client();(async () => { await client.connect() const res = await client.query('SELECT $1::text as message', ['Hello world!']) console.log(res.rows[0].message) // Hello world! await client.end()})()
GraphQl nodejs
type Query {
info: String!
feed(
filter: String
skip: Int
take: Int
orderBy: LinkOrderByInput
): Feed!
}
type Feed {
id: ID!
links: [Link!]!
count: Int!
}
type Mutation {
post(url: String!, description: String!): Link!
signup(
email: String!
password: String!
name: String!
): AuthPayload
login(email: String!, password: String!): AuthPayload
vote(linkId: ID!): Vote
}
type Subscription {
newLink: Link
newVote: Vote
}
type AuthPayload {
token: String
user: User
}
type User {
id: ID!
name: String!
email: String!
links: [Link!]!
}
type Link {
id: ID!
description: String!
url: String!
postedBy: User
votes: [Vote!]!
createdAt: DateTime!
}
type Vote {
id: ID!
link: Link!
user: User!
}
input LinkOrderByInput {
description: Sort
url: Sort
createdAt: Sort
}
enum Sort {
asc
desc
}
scalar DateTime
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us