Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1.0] Relay Compiler #912

Merged
merged 34 commits into from
May 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
632c019
Relay integration
jquense May 3, 2017
770c2c1
what is the deal with eslint
jquense May 3, 2017
6c10b67
gatsbygram update
jquense May 3, 2017
1272e07
Hacker News example
jquense May 3, 2017
77f773d
Drupal example
jquense May 3, 2017
d5a50ff
bonus dependency
jquense May 3, 2017
e5204e8
Merge branch '1.0' into gatsbyjs-relay
KyleAMathews May 3, 2017
526805a
Missed adding this
KyleAMathews May 3, 2017
26ec75a
Actually format example code
KyleAMathews May 3, 2017
2b8e88c
update dependencies
KyleAMathews May 3, 2017
f4c574d
Get types for nested arguments + handle argument lists
KyleAMathews May 4, 2017
7d18699
Add missing babel-runtime dependency
KyleAMathews May 4, 2017
1ca725c
Try removing hoisting to see if that fixes site builds
KyleAMathews May 4, 2017
37872d7
debugging
KyleAMathews May 4, 2017
47749a2
Updates from @jquense's changes
KyleAMathews May 4, 2017
9f0989d
Set websites to use 'canary' versions of websites so always download …
KyleAMathews May 4, 2017
0c24dce
Add required yaml-loader
KyleAMathews May 4, 2017
a3ef328
Remove yarn.locks from example sites as we always want to install the…
KyleAMathews May 4, 2017
bc04924
Update www for the new relay compiler
KyleAMathews May 4, 2017
c165c82
Lengthen debounce so stuff can really finish
KyleAMathews May 4, 2017
a09d78b
Make paths to bin relative
KyleAMathews May 4, 2017
84bd4b2
Restore lerna hoisting
KyleAMathews May 4, 2017
d7ef8aa
Add error and quit if a query name is missing
KyleAMathews May 4, 2017
709bb07
Dunno if this helps but...
KyleAMathews May 4, 2017
9867624
Fix version string
KyleAMathews May 4, 2017
26781a4
debugging...
KyleAMathews May 4, 2017
9bfbb8c
More info
KyleAMathews May 4, 2017
b8c3205
Follow links
KyleAMathews May 4, 2017
a874d6e
Add netlify.toml to set yarn version
KyleAMathews May 4, 2017
e0229d4
Turned out not what we want
KyleAMathews May 4, 2017
4303e59
Get around permission error on Netlify
KyleAMathews May 4, 2017
7efda7f
Don't overwrite the Gatsby bin directory or it'll stop working
KyleAMathews May 4, 2017
af53197
Remove this workaround
KyleAMathews May 4, 2017
2de79bd
Remove debuggin
KyleAMathews May 4, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 36 additions & 16 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"extends": [
"google",
"eslint:recommended",
"plugin:flowtype/recommended",
"plugin:react/recommended",
"prettier",
Expand All @@ -9,7 +10,7 @@
],
"plugins": [
"flowtype",
"react",
"react"
],
"parserOptions": {
"ecmaVersion": 2016,
Expand All @@ -23,19 +24,38 @@
"node": true
},
"rules": {
"valid-jsdoc": [0],
"require-jsdoc": [0],
"quotes": ["error", "backtick"],
"jsx-quotes": ["error", "prefer-double"],
"max-len": ["error", 80],
"semi": ["error", "never"],
"object-curly-spacing": ["error", "always"],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore",
}]
"no-console": "off",
"valid-jsdoc": "off",
"require-jsdoc": "off",
"quotes": [
"error",
"backtick"
],
"jsx-quotes": [
"error",
"prefer-double"
],
"max-len": [
"error",
80
],
"semi": [
"error",
"never"
],
"object-curly-spacing": [
"error",
"always"
],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "ignore"
}
]
}
}
}
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn.lock
8 changes: 8 additions & 0 deletions examples/gatsbygram/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"env": {
"browser": true
},
"globals": {
"graphql": false
}
}
2 changes: 1 addition & 1 deletion examples/gatsbygram/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exports.createPages = ({ graphql, boundActionCreators }) => {
// from static data that you can run queries against.
//
// Post is a data node type derived from data/posts.json
// which is created when scrapping Instagram. “allPosts
// which is created when scrapping Instagram. “allPostsJson
// is a "connection" (a GraphQL convention for accessing
// a list of nodes) gives us an easy way to query all
// Post nodes.
Expand Down
25 changes: 13 additions & 12 deletions examples/gatsbygram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,24 @@
"version": "1.0.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": {
"gatsby": "1.0.0-alpha13",
"gatsby-link": "1.0.0-alpha13",
"gatsby-transformer-json": "1.0.0-alpha13",
"gatsby-transformer-sharp": "1.0.0-alpha13",
"gatsby-plugin-glamor": "1.0.0-alpha13",
"gatsby-plugin-google-analytics": "^1.0.0-alpha13",
"gatsby-plugin-manifest": "1.0.0-alpha13",
"gatsby-plugin-offline": "1.0.0-alpha13",
"gatsby-plugin-sharp": "1.0.0-alpha13",
"gatsby-source-filesystem": "1.0.0-alpha13",
"gatsby-typegen-filesystem": "1.0.0-alpha13",
"gatsby-typegen-sharp": "1.0.0-alpha13",
"gatsby": "canary",
"gatsby-link": "canary",
"gatsby-plugin-glamor": "canary",
"gatsby-plugin-google-analytics": "canary",
"gatsby-plugin-manifest": "canary",
"gatsby-plugin-offline": "canary",
"gatsby-plugin-sharp": "canary",
"gatsby-source-filesystem": "canary",
"gatsby-transformer-json": "canary",
"gatsby-transformer-sharp": "canary",
"gatsby-typegen-filesystem": "canary",
"gatsby-typegen-sharp": "canary",
"instagram-screen-scrape": "^2.0.0",
"lodash": "^4.16.4",
"mkdirp": "^0.5.1",
"mousetrap": "^1.6.0",
"progress": "^1.1.8",
"prop-types": "^15.5.8",
"react-gravatar": "^2.6.1",
"react-icons": "^2.2.3",
"react-modal": "^1.7.6",
Expand Down
48 changes: 48 additions & 0 deletions examples/gatsbygram/src/components/Avatar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import * as PropTypes from "prop-types"
import React from "react"
import { rhythm } from "../utils/typography"

const propTypes = {
user: PropTypes.shape({
avatar: PropTypes.string.isRequired,
username: PropTypes.string.isRequired,
}),
}

function Avatar({ user }) {
return (
<img
src={user.avatar}
alt={user.username}
css={{
display: `block`,
margin: `0 auto`,
borderRadius: `100%`,
width: rhythm(2),
height: rhythm(2),
[`@media (min-width: 460px)`]: {
width: rhythm(3),
height: rhythm(3),
},
[`@media (min-width: 525px)`]: {
width: rhythm(4),
height: rhythm(4),
},
[`@media (min-width: 600px)`]: {
width: `inherit`,
height: `inherit`,
},
}}
/>
)
}

Avatar.propTypes = propTypes

export default Avatar
export const userFragment = graphql`
fragment Avatar_user on PostsJson {
avatar
username
}
`
59 changes: 36 additions & 23 deletions examples/gatsbygram/src/components/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,31 @@ import Close from "react-icons/lib/md/close"
import findIndex from "lodash/findIndex"
import mousetrap from "mousetrap"

import { rhythm, scale } from "../utils/typography"
import { rhythm } from "../utils/typography"

class GatsbyGramModal extends React.Component {
static propTypes = {
isOpen: React.PropTypes.bool,
location: React.PropTypes.object.isRequired,
posts: React.PropTypes.array.isRequired,
}

componentDidMount() {
mousetrap.bind("left", () => this.previous())
mousetrap.bind("right", () => this.next())
mousetrap.bind("spacebar", () => this.next())
mousetrap.bind(`left`, () => this.previous())
mousetrap.bind(`right`, () => this.next())
mousetrap.bind(`spacebar`, () => this.next())
}

componentWillUnmount() {
mousetrap.unbind("left")
mousetrap.unbind("right")
mousetrap.unbind("spacebar")
mousetrap.unbind(`left`)
mousetrap.unbind(`right`)
mousetrap.unbind(`spacebar`)
}

findCurrentIndex() {
let index
index = findIndex(this.props.edges, edge => {
return edge.node.id === this.props.location.pathname.split(`/`)[1]
index = findIndex(this.props.posts, post => {
return post.id === this.props.location.pathname.split(`/`)[1]
})

return index
Expand All @@ -37,15 +43,15 @@ class GatsbyGramModal extends React.Component {
}
const currentIndex = this.findCurrentIndex()
if (currentIndex || currentIndex === 0) {
const edges = this.props.edges
const posts = this.props.posts
let nextPost
// Wrap around if at end.
if (currentIndex + 1 === edges.length) {
nextPost = edges[0]
if (currentIndex + 1 === posts.length) {
nextPost = posts[0]
} else {
nextPost = edges[currentIndex + 1]
nextPost = posts[currentIndex + 1]
}
browserHistory.push(`/${nextPost.node.id}/`)
browserHistory.push(`/${nextPost.id}/`)
}
}

Expand All @@ -55,15 +61,15 @@ class GatsbyGramModal extends React.Component {
}
const currentIndex = this.findCurrentIndex()
if (currentIndex || currentIndex === 0) {
const edges = this.props.edges
const posts = this.props.posts
let previousPost
// Wrap around if at start.
if (currentIndex === 0) {
previousPost = edges.slice(-1)[0]
previousPost = posts.slice(-1)[0]
} else {
previousPost = edges[currentIndex - 1]
previousPost = posts[currentIndex - 1]
}
browserHistory.push(`/${previousPost.node.id}/`)
browserHistory.push(`/${previousPost.id}/`)
}
}

Expand All @@ -74,24 +80,24 @@ class GatsbyGramModal extends React.Component {
onRequestClose={() => browserHistory.push(`/`)}
style={{
overlay: {
position: "fixed",
position: `fixed`,
top: 0,
left: 0,
right: 0,
bottom: 0,
backgroundColor: "rgba(0, 0, 0, 0.75)",
backgroundColor: `rgba(0, 0, 0, 0.75)`,
},
content: {
position: "absolute",
position: `absolute`,
border: `none`,
background: `none`,
padding: 0,
top: 0,
bottom: 0,
right: 0,
left: 0,
overflow: "auto",
WebkitOverflowScrolling: "touch",
overflow: `auto`,
WebkitOverflowScrolling: `touch`,
},
}}
contentLabel="Modal"
Expand Down Expand Up @@ -152,3 +158,10 @@ class GatsbyGramModal extends React.Component {
}

export default GatsbyGramModal

export const modalFragment = graphql`
fragment Modal_posts on PostsJson {
id
}

`
36 changes: 33 additions & 3 deletions examples/gatsbygram/src/components/post-detail.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react"
import HeartIcon from "react-icons/lib/fa/heart"

import presets from "../utils/presets"
import typography, { rhythm, scale } from "../utils/typography"
Expand All @@ -11,15 +10,16 @@ class PostDetail extends React.Component {

render() {
const {
image,
bigImage,
likes,
id,
username,
weeksAgo,
text,
avatar,
} = this.props.post
const { big } = image.childImageSharp

const { big } = bigImage.childImageSharp

const UserBar = () => (
<div
Expand Down Expand Up @@ -191,3 +191,33 @@ class PostDetail extends React.Component {
}

export default PostDetail

export const postDetailFragment = graphql`
fragment PostDetail_details on PostsJson {
# Specify the fields from the post we need.
username
avatar
likes
id
text
# Date fields have special arguments. This one computes
# how many weeks have passed since the post was created.
# All calculations like this (like all GraphQL query
# activity) happens at build-time! So has minimal cost
# for the client.
weeksAgo: time(difference: "weeks")
bigImage: image {
childImageSharp {
# Here we query for *multiple* image thumbnails to be
# created. So with no effort on our part, 100s of
# thumbnails are created. This makes iterating on
# designs effortless as we simply change the args
# for the query and we get new thumbnails.
big: responsiveSizes(maxWidth: 640) {
src
srcSet
}
}
}
}
`
Loading