Skip to content

Instantly share code, notes, and snippets.

View zapkub's full-sized avatar
🦄
Doing FINE !

Rungsikorn Rungsikavanich zapkub

🦄
Doing FINE !
View GitHub Profile
import { USER_INFOMATION_QUERY, USER_NOTIFICATION_QUERY, USER_INFOMATION_MUTATION } from './user.graphql'
import { graphql, compose } from 'react-apollo'
import UserInfomationComponent from './user.component'
// need to defined shape of
// prop types from enhanced component
type UserInfomationContainerPropTypes = {
userId: string
import { USER_INFOMATION_QUERY, USER_NOTIFICATION_QUERY, USER_INFOMATION_MUTATION } from './user.graphql'
import { graphql, compose } from 'react-apollo'
import UserInfomationComponent from './user.component'
// need to defined shape of
// prop types from enhanced component
type UserInfomationContainerPropTypes = {
userId: string
export function graphql<
TProps extends TGraphQLVariables | {} = {},
TData = {},
TGraphQLVariables = {},
TChildProps = Partial<DataProps<TData, TGraphQLVariables>> &
Partial<MutateProps<TData, TGraphQLVariables>>
>(
document: DocumentNode,
operationOptions: OperationOption<TProps, TData, TGraphQLVariables, TChildProps> = {},
import * as React from 'react'
import { graphql } from 'react-apollo'
import gql from 'graphql-tag'
const USER_INFOMATION_QUERY = gql`
query {
user {
_id
email
@zapkub
zapkub / client.js
Created January 21, 2018 06:57
http stream with nodejs express
// on client request
const xhr = new XMLHttpRequest()
// request to api endpoint
xhr.open('post', '/documents.zip')
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8')
xhr.onprogress = () => {
// receive stream
console.log('PROGRESS:', xhr.responseText)
const momentTimeZone = require('moment-timezone');
function getBKKTime() {
const date = new Date()
const UTCDateString = date.toISOString()
const BKKDateString = moment.tz(UTCDateString, 'Asia/Bangkok').format()
return BKKDateString;
}
const rawSchema = {
typeDefs: `
type Query {
gqlTools: String
}
`,
resolvers: {
Query: {
gqlTools: () => 'Hi from gqlTools'
}
graphqlExpress(req => {
const extendContext = require('./graphql').getGraphQLExtendedContext(req)
// }
return ({
schema,
tracing,
context: {
...req,
...extendContext
},
@zapkub
zapkub / apollo-ssr.jsx
Created October 24, 2017 07:42
apollo-with-ssr-user-session
import React from 'react'
import { ApolloProvider, getDataFromTree } from 'react-apollo'
import 'isomorphic-fetch'
import { sessionQuery } from './withSession'
import apolloClientFactory from '../../common/apolloClientFactory'
export default (Component) => class withData extends React.Component {
static async getInitialProps (context) {
if (typeof window === 'undefined') {
const props = {
user: context.req.user,
.container {
background: black;
display: flex;
flex-direction: column;
position: relative;
height: 100vh;
align-items: center;
justify-content: center;
box-sizing: border-box;
color: #f5f6f8;