Skip to content

Instantly share code, notes, and snippets.

@eyston
eyston / route.js
Last active October 19, 2016 13:10
Doing onEnter hooks with Relay that require data / async
const node = Relay.QL`
query {
node(id: $channelId) {
... on Channel {
joined
${JoinChannelMutation.getFragment('channel')}
}
}
}
`;
let rootValue = {
response: {
timing: {
fields: []
}
}
}
const start = new Date().getTime();
return graphql(schema, query, rootValue, variables).then(response => {
const rootValue = {
user,
client,
...root,
__timing: [] // store the timing info in here -- sorta hacky!
}
return graphql(schema, query, rootValue, variables).then(response => {
@eyston
eyston / auth.js
Last active November 5, 2015 04:08
const hasRole = (role, next) => {
return (obj, args, ctx) => {
if (ctx.rootValue.user.hasRole(role)) {
next(obj, args, ctx);
} else {
return null;
}
}
}
{
"jsonGraph": {
"organization": {
"facebook": {
"repositoriesWithCursor": {
"0": {
"$type": "ref",
"value": [
"repository",
"facebook/codemod"
query {
organization16j31a7:organization(id: "facebook") {
description,
id,
name
},
repository1awoa9m:repository(id: "facebook/react") {
description,
id,
name
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'
];
(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])]
;; ...
)
(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)
{: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