Skip to content

Instantly share code, notes, and snippets.

@eyston
eyston / route.js
Last active Oct 19, 2016
Doing onEnter hooks with Relay that require data / async
View route.js
const node = Relay.QL`
query {
node(id: $channelId) {
... on Channel {
joined
${JoinChannelMutation.getFragment('channel')}
}
}
}
`;
View graphql.js
let rootValue = {
response: {
timing: {
fields: []
}
}
}
const start = new Date().getTime();
return graphql(schema, query, rootValue, variables).then(response => {
View 1.js
const rootValue = {
user,
client,
...root,
__timing: [] // store the timing info in here -- sorta hacky!
}
return graphql(schema, query, rootValue, variables).then(response => {
View auth.js
const hasRole = (role, next) => {
return (obj, args, ctx) => {
if (ctx.rootValue.user.hasRole(role)) {
next(obj, args, ctx);
} else {
return null;
}
}
}
View jsonGraph.json
{
"jsonGraph": {
"organization": {
"facebook": {
"repositoriesWithCursor": {
"0": {
"$type": "ref",
"value": [
"repository",
"facebook/codemod"
View query.graphql
query {
organization16j31a7:organization(id: "facebook") {
description,
id,
name
},
repository1awoa9m:repository(id: "facebook/react") {
description,
id,
name
View history.js
import RelayStoreData from 'react-relay/lib/RelayStoreData';
import RelayQueryPath from 'react-relay/lib/RelayQueryPath';
import printRelayQuery from 'react-relay/lib/printRelayQuery';
import {List,Map} from 'immutable';
var REMOVE_KEYS = [
'_storage'
];
View getter.clj
(def graph {:roots {} :nodes {}})
;; end up wit ha structure like this after adding a node
(def graph {:roots {} :nodes {'Organization {:fields {:id {}}}}})
;; do I do this?
(let [field (get-in graph [:nodes 'Organization :fields :id])]
;; ...
)
View stream.clj
(defn paged-http-get
([url]
(paged-http-get url 1))
([url page]
(let [sink (s/stream)]
(d/loop [page page]
(d/chain (http-get url {:query-params {"page" page}})
(fn [response]
(let [body (:body response)]
(if (seq body)
View request.clj
{:name nil
:description nil
:email nil
:repositories {:count nil
:filters {:first {:count 50}
:after {:cursor 22046023}}
:edges {:cursor nil
:node {:id nil
:name nil
:full_name nil
You can’t perform that action at this time.