Skip to content

Instantly share code, notes, and snippets.

View Wonder2210's full-sized avatar
💭
Achiving new goals

Wonder Wonder2210

💭
Achiving new goals
View GitHub Profile
@Wonder2210
Wonder2210 / app.js
Last active December 3, 2019 03:56
Basic initialization store for React + Redux projects using connected-react-router and redux thunk
import
React,{Component
}from 'react';
import {Route,Switch} from 'react-router';
import {Link} from 'react-router-dom';
import {ConnectedRouter} from 'connected-react-router';
import {history} from './store';
import {Provider} from 'react-redux';
import {configureStore} from './store';
![Captura](https://user-images.githubusercontent.com/29363763/77968943-1213a080-72d8-11ea-97b6-b44a5e812006.PNG)
@Wonder2210
Wonder2210 / index.ts
Last active May 29, 2020 03:21
Postgresql + Graphql + Typescript server Hello world
import express, { Application } from 'express';
import { ApolloServer , Config } from 'apollo-server-express';
const app: Application = express();
const schema = `
type User{
name: String
@Wonder2210
Wonder2210 / webpack.config.js
Created May 29, 2020 03:24
Webpack config for Graphql + Typescript
const path = require('path');
const {CheckerPlugin} = require('awesome-typescript-loader');
var nodeExternals = require('webpack-node-externals');
module.exports = {
mode: 'production',
entry: './src/index.ts',
target:'node',
externals: [nodeExternals(),{ knex: 'commonjs knex' }],
output: {
@Wonder2210
Wonder2210 / tsconfig.json
Created May 29, 2020 03:27
Tsconfig for most cases
{
"compilerOptions": {
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */
/* Concatenate and emit output to single file. */
"outDir": "dist", /* Redirect output structure to the directory. */
"rootDir": "src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */
@Wonder2210
Wonder2210 / migration.ts
Created May 29, 2020 03:30
Easy database Schema migration with knex
import * as Knex from "knex";
export async function up(knex: Knex): Promise<any> {
return knex.schema.createTable('users',(table:Knex.CreateTableBuilder)=>{
table.increments('id');
table.string('full_name',36);
table.integer('country_code');
table.timestamps(true,true);
@Wonder2210
Wonder2210 / knexfile.ts
Created May 29, 2020 03:34
Basic knex config
require('ts-node/register');
module.exports = {
development:{
client: 'pg',
connection: {
database: "my_db",
user: "username",
password: "password"
@Wonder2210
Wonder2210 / Pet.ts
Created May 29, 2020 03:40
Models for PG-Graphql-TS
import {Model} from 'objection';
import {Species,Maybe} from '../../__generated__/generated-types';
import User from './User';
class Pet extends Model{
static tableName = "pets";
id! : number;
name?: Maybe<string>;
specie?: Maybe<Species>;
@Wonder2210
Wonder2210 / schema.gql
Last active May 29, 2020 04:38
Basic Graphql schema
enum Species{
BIRDS,
FISH,
MAMMALS,
REPTILES
}
type User {
id: Int!
full_name: String
@Wonder2210
Wonder2210 / pet.ts
Last active May 29, 2020 04:36
resolvers
import {Pet,User} from '../../database/models';
import {Resolvers} from '../../__generated__/generated-types';
import {UserInputError} from 'apollo-server-express';
const resolvers : Resolvers = {
Query:{
pet:async (parent,args,ctx)=>{
const pet:Pet= await Pet.query().findById(args.id);