Skip to content

Instantly share code, notes, and snippets.

View peterj's full-sized avatar
🌟
....

Peter Jausovec peterj

🌟
....
View GitHub Profile
import React, { Component } from 'react';
import Link from './Link';
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
const ALL_LINKS_QUERY = gql`
query AllLinksQuery {
allLinks {
id
createHash = (itemCount) => {
let hashDigits = [];
// dividend is a unique integer (in our case, number of links)
let dividend = itemCount + 1;
let remainder = 0;
while (dividend > 0) {
remainder = dividend % 62;
dividend = Math.floor(dividend / 62);
hashDigits.unshift(remainder);
}
@peterj
peterj / snippet.js
Last active December 29, 2017 18:22
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
const CREATE_SHORT_LINK_MUTATION = gql`
mutation CreateLinkMutation($url: String!, $description: String!, $hash: String!) {
createLink(url: $url, description: $description, hash: $hash) {
id
}
}
`;
@peterj
peterj / snippet1.js
Last active January 17, 2018 11:36
import React, { Component } from 'react';
import gql from 'graphql-tag';
import { graphql, withApollo } from 'react-apollo';
const CREATE_SHORT_LINK_MUTATION = gql`
mutation CreateLinkMutation($url: String!, $description: String!) {
createLink(url: $url, description: $description) {
id
}
import React, { Component } from 'react';
import LinkList from './components/LinkList';
import CreateShortLink from './components/CreateShortLink';
class App extends Component {
render() {
return (
<div>
<div>
<h2>All links</h2>
const LINKS_SUBSCRIPTION = gql`
subscription NewLinkCreatedSubscription {
Link(filter: { mutation_in: [CREATED] }) {
node {
id
url
description
hash
}
}
componentDidMount() {
this.props.allLinksQuery.subscribeToMore({
document: LINKS_SUBSCRIPTION,
updateQuery: (prev, { subscriptionData }) => {
const newLinks = [
...prev.allLinks,
subscriptionData.data.Link.node,
];
const result = {
...prev,