Skip to content

Commit

Permalink
fix(examples): remove using-fragments submodule (#16808)
Browse files Browse the repository at this point in the history
* remove submodule for fragments

* add fragments example back as folder
  • Loading branch information
gillkyle authored and GatsbyJS Bot committed Aug 20, 2019
1 parent 780c62a commit 63984c7
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 1 deletion.
1 change: 0 additions & 1 deletion examples/using-fragments
Submodule using-fragments deleted from 1e7a36
21 changes: 21 additions & 0 deletions examples/using-fragments/LICENSE
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 gatsbyjs

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
3 changes: 3 additions & 0 deletions examples/using-fragments/README.md
@@ -0,0 +1,3 @@
# Using Fragments Example

This repo contains a simplified example of using GraphQL fragments in a Gatsby site
19 changes: 19 additions & 0 deletions examples/using-fragments/gatsby-config.js
@@ -0,0 +1,19 @@
/**
* Configure your Gatsby site with this file.
*
* See: https://www.gatsbyjs.org/docs/gatsby-config/
*/

module.exports = {
siteMetadata: {
title: `GatsbyJS`,
details: {
url: `https://www.gatsbyjs.org`,
description: `Blazing fast modern site generator for React`,
},
social: {
twitter: `@gatsbyjs`,
},
},
/* Your site config here */
}
30 changes: 30 additions & 0 deletions examples/using-fragments/package.json
@@ -0,0 +1,30 @@
{
"name": "using-fragments",
"private": true,
"description": "A simplified example of using GraphQL fragments",
"version": "0.1.0",
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
"serve": "gatsby serve",
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
},
"dependencies": {
"gatsby": "^2.13.63",
"react": "^16.9.0",
"react-dom": "^16.9.0"
},
"devDependencies": {
"prettier": "^1.18.2"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}
22 changes: 22 additions & 0 deletions examples/using-fragments/src/components/details.js
@@ -0,0 +1,22 @@
import React from "react"
import { graphql } from "gatsby"

const Details = ({ data }) => (
<div>
{data.site.siteMetadata.details.url} -{` `}
{data.site.siteMetadata.details.description}
</div>
)

export default Details

export const detailsFragment = graphql`
fragment DetailsFragment on Site {
siteMetadata {
details {
url
description
}
}
}
`
16 changes: 16 additions & 0 deletions examples/using-fragments/src/components/social.js
@@ -0,0 +1,16 @@
import React from "react"
import { graphql } from "gatsby"

const Social = ({ data }) => <div>{data.site.siteMetadata.social.twitter}</div>

export default Social

export const socialFragment = graphql`
fragment SocialFragment on Site {
siteMetadata {
social {
twitter
}
}
}
`
45 changes: 45 additions & 0 deletions examples/using-fragments/src/pages/index.js
@@ -0,0 +1,45 @@
import React from "react"
import { graphql } from "gatsby"
import Details from "../components/details"
import Social from "../components/social"

export default ({ data }) => (
<div>
Hello world! This is {data.site.siteMetadata.title}
<Details data={data} />
<Social data={data} />
</div>
)

export const pageQuery = graphql`
query SiteQuery {
site {
siteMetadata {
title
}
...DetailsFragment
...SocialFragment
}
}
`

/*
instead of...
export const pageQuery = graphql`
query SiteQuery {
site {
siteMetadata {
title
details {
url
description
}
social {
twitter
}
}
}
}
`
*/

0 comments on commit 63984c7

Please sign in to comment.