Skip to content

Instantly share code, notes, and snippets.

View guzmonne's full-sized avatar

Guzman Monne guzmonne

  • Uruguay
  • Montevideo, Uruguay
View GitHub Profile
@guzmonne
guzmonne / 002_server.js
Created March 27, 2017 00:56
Express server with GraphQL endpoint
const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const {graphqlExpress, graphiqlExpress} = require('graphql-server-express')
const schema = require('../graphql/schema.js')
const PORT = 3000
const app = express()
@guzmonne
guzmonne / 002_graphql_schema.js
Created March 27, 2017 00:59
Habitapp first graphql schema
const {merge, range, uniqueId} = require('lodash')
const {makeExecutableSchema} = require('graphql-tools')
const {
schema: clickSchema,
} = require('./clicks.schema.js')
let clicks = []
const rootSchema = [`
type Query {
@guzmonne
guzmonne / 002_ipc.js
Created March 27, 2017 01:08
Electon ipc example
// On the renderer side, we listen for the 'done' event, and for the close
// event. We also send the 'open' event when the graphql button is clicked.
ipc.on('open:graphql_window:done', (event) => {
console.log('open:graphql_window:done')
addClass(graphiql, 'hidden')
removeClass(graphiqlLoading, 'hidden')
})
ipc.on('close:graphql_window', (event) => {
console.log('close:graphql_window')
@guzmonne
guzmonne / 002_setting-up-apollo-and-redux.js
Created March 27, 2017 01:14
Redux and Apollo coniguration
// ---------------------------
// Apollo Client Configuration
// ---------------------------
import {ApolloClient, createNetworkInterface} from 'react-apollo'
export const client = new ApolloClient({
networkInterface: createNetworkInterface({
addTypename: true,
dataIdFromObject: (result) => (
result._id && result.__typename
@guzmonne
guzmonne / 002_setting-up-apollo-and-redux.js
Created March 27, 2017 01:16
Setting up Apollo and Redux
// ---------------------------
// Apollo Client Configuration
// ---------------------------
import {ApolloClient, createNetworkInterface} from 'react-apollo'
export const client = new ApolloClient({
networkInterface: createNetworkInterface({
uri: 'http://localhost:3000/graphql'
}),
addTypename: true,
@guzmonne
guzmonne / Click.js
Created March 27, 2017 01:20
Dummy component to test Apollo's integration
import React from 'react'
import {gql, graphql} from 'react-apollo'
import update from 'immutability-helper'
import Click from '../components/Click.js'
class ClickContainer extends React.Component {
state = {
message: '',
}
@guzmonne
guzmonne / index.js
Created March 27, 2017 01:23
Helper component to avoid a race condition between windows.
import React from 'react';
import ReactDOM from 'react-dom';
import Root from './containers/Root.js';
import configureStore from './store/configureStore.js'
import './_styles/index.css';
const Loading = () => (<h1>Loading...</h1>)
const store = configureStore()
@guzmonne
guzmonne / Chart.js
Created April 15, 2017 02:53
Chart.js
import React from 'react'
import T from 'prop-types'
import uniqueId from 'lodash/uniqueId'
import isArray from 'lodash/isArray'
import {IMargin, IScale, IAxisOptions} from './propTypes.js'
const d3 = Object.assign({},
require('d3-selection'),
require('d3-scale'),
require('d3-array')
import React from 'react'
import T from 'prop-types'
import Chart from './Chart.js'
import D3Background from './D3Background.js'
import D3XAxis from './D3XAxis.js'
import D3YAxis from './D3YAxis.js'
import D3Bars from './D3Bars.js'
const D3SubjectBarsChart = ({data}) => (
<Chart
@guzmonne
guzmonne / SubjectBarsChart.js
Created April 15, 2017 02:57
Chart element example
import React from 'react'
import T from 'prop-types'
import Chart from './Chart.js'
import Background from './Background.js'
import Axis from './Axis.js'
import Bars from './Bars.js'
const SubjectBarsChart = ({data}) => (
<Chart
data={data}