Skip to content

Instantly share code, notes, and snippets.

View docker-install.sh
# Instructions found in the following links
# https://docs.docker.com/engine/install/ubuntu/
# https://docs.docker.com/engine/install/linux-postinstall/
#: clean previous
sudo apt-get remove docker docker-engine docker.io containerd runc
#: install
sudo apt-get update
sudo apt-get install \
View docker-compose.yml
# start: docker-compose up (-d for detached mode)
# stop: docker-compose down
version: "3.9"
services:
redis-server:
container_name: redis-server
image: 'redis:6.2-alpine'
networks:
- weally
@ziedHamdi
ziedHamdi / Dockerfile
Last active Sep 18, 2021
Example of docker file
View Dockerfile
# syntax=docker/dockerfile:1
# docker build . -t graphql:1.0.0
# docker run -d --name graphql_server graphql:1.0.0
# docker ps -a
# docker logs [name]
# docker exec -it [name] /bin/sh
# babel is under node_modules/.bin
# docker rm [name] //removes runtime conainer
# docker rm $(docker ps -a -q) //removes all stopped containers
@ziedHamdi
ziedHamdi / install.sh
Created Sep 15, 2021
build docker images from git repositories
View install.sh
#!/bin/sh
# GRAPHQL_SERVER_VERSION=$1
# NEXT_SERVER_VERSION=$2
# set variables from .env to system: https://gist.github.com/mihow/9c7f559807069a03e302605691f85572
if [ -f .env ]
then
export $(cat .env | sed 's/#.*//g' | xargs)
fi
@ziedHamdi
ziedHamdi / client.js
Created Aug 27, 2021
Apollo client.js ssr enabled
View client.js
import {useMemo} from 'react'
import {ApolloClient, gql} from '@apollo/client'
import merge from 'deepmerge'
import {cache} from './cache'
import {isSSR} from "../constants/util";
import isEqual from 'lodash/isEqual'
export const APOLLO_STATE_PROP_NAME = '__APOLLO_STATE__'
const typeDefs = gql`
@ziedHamdi
ziedHamdi / _app.js
Created Aug 27, 2021
An example of _app.js
View _app.js
import React from 'react';
import {ApolloProvider} from '@apollo/client'
import {useApollo} from '../apollo/client'
import {ThemeProvider} from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import Head from 'next/head';
import theme from '../components/theme';
import PropTypes from 'prop-types';
import {appWithTranslation} from 'next-i18next';
import {Provider} from 'next-auth/client'
@ziedHamdi
ziedHamdi / ssrPage.js
Last active Aug 27, 2021
Ssr with Apollo and Next.js: code in page
View ssrPage.js
import {gql, useQuery} from '@apollo/client'
import {Grid} from "@material-ui/core";
import {serverSideTranslations} from 'next-i18next/serverSideTranslations';
import {addApolloState, initializeApollo} from '../apollo/client'
import {getDataFromTree} from "@apollo/client/react/ssr";
export async function getServerSideProps(context) {
const client = initializeApollo({})
// await getDataFromTree(SsrPage) (not working: see bug report)
const query1 = await client.query({query: ComplaintsQuery})