Skip to content

Instantly share code, notes, and snippets.

View stubailo's full-sized avatar
📈
Working on Flipturn!

Sashko Stubailo stubailo

📈
Working on Flipturn!
View GitHub Profile
@stubailo
stubailo / filter.js
Last active December 5, 2016 19:21
graphql-anywhere filter
import gql from 'graphql-tag';
import graphql from 'graphql-anywhere';
// I don't need all this stuff!
const gitHubAPIResponse = {
"url": "https://api.github.com/repos/octocat/Hello-World/issues/1347",
"title": "Found a bug",
"body": "I'm having a problem with this.",
"user": {
"login": "octocat",
@stubailo
stubailo / redux.js
Created December 5, 2016 19:22
graphql-anywhere redux
const data = {
result: [1, 2],
entities: {
articles: {
1: { id: 1, title: 'Some Article', author: 1 },
2: { id: 2, title: 'Other Article', author: 1 },
},
users: {
1: { id: 1, name: 'Dan' },
},
@stubailo
stubailo / proptypes.jsx
Last active December 5, 2016 19:34
graphql-anywhere proptypes
import { propType } from 'graphql-anywhere';
const CommentView = ({ comment }) => (
<div>
<p>{ comment.content }</p>
<p>Posted by { comment.postedBy.login } on {comment.createdAt }</p>
</div>
);
CommentView.commentFragment = gql`
@stubailo
stubailo / docs.js
Created December 16, 2016 07:57
Why do all code docs tools put the doc in a separate comment instead of in the code?
// Quick idea. I love doc comments, but it's annoying that you need to repeat all of the
// argument names again, just to document them. It's easy for parameter lists to fall out
// of date. Plus, if you're using a typed language a lot of the information is already
// there. Is there a tool to parse comments like the below?
/** Create a Redux store. Using this function as a convenient example. */
function createStore(
/** A reducer function that maps the previous state and current action to the next state. */
reducer: ReducerFunction,
query HeroName($episode: Episode) {
hero(episode: $episode) {
...DescribeHero
}
}
fragment DescribeHero on Character {
name
appearsIn
}
@stubailo
stubailo / recompose.jsx
Last active January 22, 2019 02:05
Using Recompose to manage variables in react-apollo
import React from 'react';
import { withState, pure, compose } from 'recompose';
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
import { Link } from 'react-router';
// The data prop, which is provided by the wrapper below, contains
// a `loading` key while the query is in flight, and the bookSearch
// results when they are ready
const BookSearchResultsPure = ({ data: { loading, bookSearch } }) => {
@stubailo
stubailo / branch.jsx
Created February 11, 2017 17:27
Using branch and renderComponent to display loading state with Recompose and React-Apollo
import React from 'react';
import { pure, branch, renderComponent, compose } from 'recompose';
import gql from 'graphql-tag';
import { graphql } from 'react-apollo';
import { Link } from 'react-router';
// Define a very basic loading state component - you could make this
// a nice animation or something
const Loading = () => (
<div>Loading</div>
@stubailo
stubailo / Results.js
Created February 16, 2017 16:27
Subscription request and results
// Result 1
{
"data": {
"commentAdded": {
"comment": {
"id": "abc123",
"content": "GraphQL subscriptions will be awesome!",
"author": { "username": "sashko" }
}
}
@stubailo
stubailo / fragments.js
Last active April 19, 2017 05:47
Relay Classic fragments
// Some component that defines a fragment
Greeting = Relay.createContainer(Greeting, {
fragments: {
greetings: () => Relay.QL`
fragment on Greetings {
hello
}
`,
},
});
@stubailo
stubailo / modern.js
Last active April 19, 2017 16:09
Relay Modern fragments
// Some component that defines a fragment
Greeting = createFragmentContainer(Greeting, graphql`
fragment Greeting_greeting on Greetings {
hello
}
`);
// Some other component that uses the fragment from above
App = createFragmentContainer(App, graphql`
fragment App_greetings on Greetings {