Skip to content

Instantly share code, notes, and snippets.

View jtn-ms's full-sized avatar
🏘️
working from home

Brian G. jtn-ms

🏘️
working from home
  • remote
View GitHub Profile
@jtn-ms
jtn-ms / models.client.js
Last active July 20, 2022 17:14
mongoose - model, schema, pure type
const mongoose = require('mongoose');
const ClientSchema = new mongoose.Schema({
name: {
type:String,
},
email : {
type: String,
},
phone: {
type: String,
@jtn-ms
jtn-ms / config.db.js
Last active July 20, 2022 17:02
mongoose + graphql
const mongoose = require('mongoose');
const connectDB = async () => {
const conn = await mongoose.connect(process.env.MONGODB_URL);
console.log(`MongoDB connected: ${conn.connection.host}`.cyan.underline.bold);
};
module.exports = connectDB;
@jtn-ms
jtn-ms / schema-pureType.js
Last active July 20, 2022 17:03
no database - graphql
// Client Type
const ClientType = new GraphQLObjectType({
name: 'Client',
fields: () =>({
id: {type: GraphQLID},
name: {type: GraphQLString},
email: {type: GraphQLString},
phone: {type: GraphQLString},
})
});
@jtn-ms
jtn-ms / schema-mixedType.js
Last active July 20, 2022 17:04
no database - graphql
const ProjectType = new GraphQLObjectType({
name: 'Prject',
fields: () =>({
id: {type: GraphQLID},
name: {type: GraphQLString},
description: {type: GraphQLString},
status: {type: GraphQLString},
client: {
type: ClientType,
resolve(parent,args) { return clients.find(client => client.id === parent.clientId); }
@jtn-ms
jtn-ms / schema-queryOne.js
Last active July 20, 2022 17:11
no database - array.find
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
client: {
type:ClientType,
args: {id:{type:GraphQLID}},
resolve(parent,args) { return clients.find(client => client.id === args.id); }
}
}
})
@jtn-ms
jtn-ms / schema-queryAll.js
Last active July 20, 2022 17:12
no database - array
const RootQuery = new GraphQLObjectType({
name: 'RootQueryType',
fields: {
clients: {
type: new GraphQLList(ClientType),
resolve(parent,args) { return clients;}
},
}
})
@jtn-ms
jtn-ms / express-graphql.md
Last active July 20, 2022 16:26
no database

SetUp

$ npm init -y
$ npm i express express-graphql graphql mongoose cors colors
$ npm I -D nodemon dotenv 

Nodemon

{
 "scripts": {
@jtn-ms
jtn-ms / Header.js
Created July 20, 2022 10:26
React- Search Form.md
import { useState } from 'react'
import './Header.scss'
import {Link} from 'react-router-dom';
import {fetchAsyncMovies} from '../../features/movies/movieSlice';
import {useDispatch} from 'react-redux';
export default function Header() {
const [keyword,setKeyword] = useState('');
const dispatch = useDispatch();
@jtn-ms
jtn-ms / App.js
Created July 20, 2022 10:12
Dynamic Routing - Content Management System
import './App.scss';
import Header from './components/Header/Header';
import Footer from './components/Footer/Footer';
import Home from './components/Home/Home';
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
import MovieDetail from './components/MovieDetail/MovieDetail';
function App() {
return (
<Router>
@jtn-ms
jtn-ms / examples.bat
Last active July 20, 2022 04:43
Windows Commands - bat, ps
for /l %i in (1,2,10) do echo %i
for %name in (A B C D E F) do echo %name
for /f %%url in (download.lst) do (git clone %%url)