Skip to content

Instantly share code, notes, and snippets.

View jgilbertcastro's full-sized avatar
🎯
Focusing

Jesus Gilbert jgilbertcastro

🎯
Focusing
View GitHub Profile
const express = require('express');
const ExpressGraphQL = require("express-graphql");
const schema = require("./graphql/post/post.js");
const app = express();
app.use("/graphql", ExpressGraphQL({ schema: schema.schema, graphiql: true}));
app.listen(4000, () => {
console.log("GraphQL server running at http://localhost:4000.");
});
@jgilbertcastro
jgilbertcastro / post.js
Last active August 21, 2020 12:27
post.js
const graphql = require("graphql");
const sqlite3 = require('sqlite3').verbose();
//create a database if no exists
const database = new sqlite3.Database("../micro-blog.db");
//create a table to insert post
const createPostTable = () => {
const query = `
CREATE TABLE IF NOT EXISTS posts (
@jgilbertcastro
jgilbertcastro / js
Created November 7, 2019 17:13
add post
query{
Posts{
id,
title,
description,
createDate,
author
}
}
@jgilbertcastro
jgilbertcastro / js
Created November 7, 2019 17:14
create
mutation {
createPost(title: "Mi primer Post", description: "en mi primer post tengo que la vida no es facil", createDate:"25-09-2019",author:"Jesus GIlbert") {
id,
title,
description,
createDate,
author
}
}
@jgilbertcastro
jgilbertcastro / js
Created November 7, 2019 17:16
update
mutation {
updatePost(
id:2,
title: "Mi segundo Post",
description: "en mi primer post tengo que la vida no es facil",
createDate:"26-09-2019",
author:"Jesus GIlbert"
)
}
@jgilbertcastro
jgilbertcastro / js
Created November 7, 2019 17:18
delete
mutation {
deletePost(id:1)
}
import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
//import apolloclient and vueapollo
import ApolloClient from "apollo-boost";
import VueApollo from "vue-apollo";
Vue.config.productionTip = false;
// define const apolloClient to set graphql api url
<template>
<div>
<div v-for="post in Posts" :key="post.id">
<div style="font-size: 20px; font-weight: 700;">{{ post.title }}</div>
<div style="text-align: justify; width:800px; margin:0 auto;">
<p>
{{ post.description }}
</p>
</div>
<div style="text-align: right; width:800px; margin:0 auto;">
<template>
<div>
<div v-for="post in Posts" :key="post.id">
<div style="font-size: 20px; font-weight: 700;">{{ post.title }}</div>
<div style="text-align: justify; width:800px; margin:0 auto;">
<p>
{{ post.description }}
</p>
</div>
<div style="text-align: right; width:800px; margin:0 auto;">
<template>
<div>
<div style="text-align: left; width:800px; margin:0 auto;">
<strong>Title</strong>
</div>
<div style="text-align: center; width:800px; margin:0 auto;">
<input style="width:800px" type="text" id="title" name="title" value="" v-model="title" />
</div>
<br />
<div style="text-align: left; width:800px; margin:0 auto;">