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

feat(gatsby): allow schema customization #11480

Merged
merged 111 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
9926e2d
Schema refactor WIP
freiksenet Feb 1, 2019
d9e6873
Oops
freiksenet Feb 1, 2019
08ab5c2
First working version
freiksenet Feb 4, 2019
1aef564
First working version
freiksenet Feb 4, 2019
ac49f5b
Almost working site
freiksenet Feb 4, 2019
f369296
progress
freiksenet Feb 5, 2019
6add8d9
WWW working
freiksenet Feb 6, 2019
2e25030
Working add type defs
freiksenet Feb 7, 2019
b532d1b
addResolvers
freiksenet Feb 8, 2019
69162b6
Add node model
stefanprobst Feb 8, 2019
b9af766
Handle NonNull and pass context and info in runQuery
stefanprobst Feb 9, 2019
a5b0d55
Don't fetch resolved id again
stefanprobst Feb 9, 2019
f7d80f0
Minor fixes
stefanprobst Feb 9, 2019
23423db
Make www build with Loki
stefanprobst Feb 9, 2019
6e11926
Fix tests
stefanprobst Feb 10, 2019
ed9314b
Pull out resolving nodes
stefanprobst Feb 10, 2019
79754e6
Fix getExampleValue
stefanprobst Feb 10, 2019
6f1e715
Port exampleValue tests
stefanprobst Feb 10, 2019
12a9819
Fixes for type inference
stefanprobst Feb 10, 2019
0ca1294
Infer errors and stuff
freiksenet Feb 11, 2019
b8d0d6f
Merge remote-tracking branch 'stefanprobst/schema-refactor-new-sp' in…
freiksenet Feb 11, 2019
15df9e3
Lint
freiksenet Feb 11, 2019
9a59b47
More changes
freiksenet Feb 12, 2019
7878818
Fix issue with default resolvers
freiksenet Feb 12, 2019
779cb39
Fix tests
freiksenet Feb 12, 2019
d45c97c
Port more tests
freiksenet Feb 12, 2019
10f1405
Move schema composer creation to separate location
freiksenet Feb 13, 2019
c7b1177
Most tests pass
freiksenet Feb 13, 2019
8dbc6e7
Move tests to better location
freiksenet Feb 13, 2019
bf02578
Readd list sorting option
freiksenet Feb 13, 2019
b6ec46f
Node model as a class
freiksenet Feb 13, 2019
add0666
Model layer tests
freiksenet Feb 13, 2019
da8469d
Fix flow type
freiksenet Feb 14, 2019
e7bb44b
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Feb 14, 2019
d002f9c
Restore prepare-nodes improvements
freiksenet Feb 14, 2019
73a1f2d
Fixes
freiksenet Feb 14, 2019
448bcfe
Port more tests (#11757)
stefanprobst Feb 14, 2019
2c0b2cf
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Feb 14, 2019
292200f
WIP kitchen sink
freiksenet Feb 14, 2019
1cb0aab
Fix tests for Loki, and minor changes (#11765)
stefanprobst Feb 15, 2019
e512743
Satisfy linter
freiksenet Feb 15, 2019
017bfa1
Mix dates and strings behaviour
freiksenet Feb 15, 2019
ccb0bb6
Test more stuff with runQuery
freiksenet Feb 15, 2019
58297c7
Add resolvers test
freiksenet Feb 15, 2019
1d4272e
Updated API names to match gatsby
freiksenet Feb 18, 2019
7666727
3rd party schema tests
freiksenet Feb 18, 2019
7e0261f
More fixes
freiksenet Feb 18, 2019
7f661eb
Beter example in using-type-defs
freiksenet Feb 18, 2019
3ddcf99
More fixes
freiksenet Feb 18, 2019
ff85e86
Add NodeModel tests (#11880)
stefanprobst Feb 19, 2019
31b11f3
[schema] Better example (#11892)
stefanprobst Feb 19, 2019
0c5e13a
Fix conflicting field issue
freiksenet Feb 19, 2019
a440e8e
Handle multiple return values from setFieldsOnGraphQLNodeType (#12048)
stefanprobst Feb 25, 2019
c310140
Fix conflicting fields priority on nested type (#11900)
stefanprobst Feb 25, 2019
c6a7826
Merge remote-tracking branch 'upstream/master' into schema-refactor-new
stefanprobst Feb 26, 2019
4dfc057
Allow field type on third-party type (#11970)
stefanprobst Feb 27, 2019
879cd7b
Make original field resolver available on info (#12159)
stefanprobst Feb 28, 2019
fbfa6b4
[schema] Make output fields non-null (#12097)
stefanprobst Feb 28, 2019
a1c01a6
[schema] Add schema query tests, inference fixes (#12190)
stefanprobst Mar 1, 2019
e344292
[schema] Add default page dependency path (#12220)
stefanprobst Mar 1, 2019
5db668a
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Mar 4, 2019
9992c12
chore(release): Publish
freiksenet Mar 4, 2019
ab9ffac
More tests and some fixes
freiksenet Mar 4, 2019
6cc1992
Revert "chore(release): Publish"
freiksenet Mar 4, 2019
b90b05f
Allow custom resolveType (#12309)
stefanprobst Mar 5, 2019
238cc2b
v2.2.0-alpha.0
freiksenet Mar 4, 2019
b706829
More fixes and tests
freiksenet Mar 5, 2019
9269305
More tests, refine infer logic
freiksenet Mar 5, 2019
52d6012
[schema] Make id field on InputObjectType type String (#12335)
stefanprobst Mar 6, 2019
1e58b54
v2.2.0-alpha.1
freiksenet Mar 5, 2019
7eda0b2
Upgrade schema composer
freiksenet Mar 6, 2019
222f3da
v2.2.0-alpha.2
freiksenet Mar 6, 2019
e76e7e8
Fix loxi test issue
freiksenet Mar 6, 2019
fe5fe1d
Add type builders internally
freiksenet Mar 6, 2019
081fa15
Add type builders internally
freiksenet Mar 6, 2019
f3a7cf6
Added type builders to the API
freiksenet Mar 6, 2019
5522c28
v2.2.0-alpha.3
freiksenet Mar 6, 2019
67ee427
[schema] Add NodeModel docs (#12354)
stefanprobst Mar 7, 2019
8628a48
Check for type names reserved for internal use (#12373)
stefanprobst Mar 7, 2019
4e09a7d
Allow custom scalars in input filter (#12375)
stefanprobst Mar 7, 2019
3e06835
Correctly camelcase connections (#12378)
stefanprobst Mar 7, 2019
587e9ef
v2.2.0-alpha.4
freiksenet Mar 7, 2019
16dab78
v2.2.0-alpha.5
freiksenet Mar 7, 2019
5a9a5f0
[schema] Remove empty input fields (#12380)
stefanprobst Mar 8, 2019
6c86d28
[schema] Add code frame to SDL parsing error (#12401)
stefanprobst Mar 8, 2019
ef567f0
Merge branch 'master' into schema-refactor-new
freiksenet Mar 8, 2019
582bd94
v2.2.0-alpha.6
freiksenet Mar 8, 2019
d61a776
Add blog post
freiksenet Mar 12, 2019
3f3e8fe
Don't use npx in example README
muescha Mar 16, 2019
71c391f
Update docs for new documentationjs version (#12615)
stefanprobst Mar 18, 2019
75da5e5
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Mar 18, 2019
1bc4013
v2.2.0-rc.1
freiksenet Mar 18, 2019
0a3a750
Revert "v2.2.0-rc.1"
freiksenet Mar 18, 2019
59a2dd2
Remove extra dep
freiksenet Mar 18, 2019
511abb3
Fix date
freiksenet Mar 18, 2019
f46154b
chore(blog): add schema customization blog post release (#12522)
DSchau Mar 18, 2019
582db20
Update blog as per review
freiksenet Mar 18, 2019
50ed38b
Docs
freiksenet Mar 18, 2019
4a6b108
Update docs/blog/2019-03-18-releasing-new-schema-customization/index.md
stefanprobst Mar 18, 2019
ecf5656
Add tweet
freiksenet Mar 18, 2019
0a48280
Update docs/blog/2019-03-18-releasing-new-schema-customization/index.md
stefanprobst Mar 18, 2019
3f2c4a0
Merge remote-tracking branch 'origin/master' into schema-refactor-new
freiksenet Mar 18, 2019
5c2b25a
Remove dep
stefanprobst Mar 18, 2019
c7c7ae0
Move tweet
freiksenet Mar 18, 2019
78cbab4
[schema] Ignore empty strings in example value creation (#12646)
stefanprobst Mar 19, 2019
7d48322
Add tests
freiksenet Mar 19, 2019
196ef58
Fix snapshot
freiksenet Mar 19, 2019
09f0d91
v2.2.0-rc.2
freiksenet Mar 19, 2019
4dcb431
Revert "v2.2.0-rc.2"
freiksenet Mar 19, 2019
54ff3b6
Change blog date
freiksenet Mar 19, 2019
04f7694
use <PROJECT_ROOT> in fixture (#12662)
pieh Mar 19, 2019
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
69 changes: 69 additions & 0 deletions examples/using-type-definitions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# dotenv environment variables file
.env

# gatsby files
.cache/
public

# Mac files
.DS_Store

# Yarn
yarn-error.log
.pnp/
.pnp.js
# Yarn Integrity file
.yarn-integrity
5 changes: 5 additions & 0 deletions examples/using-type-definitions/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"semi": false,
"singleQuote": true,
"trailingComma": "es5"
}
22 changes: 22 additions & 0 deletions examples/using-type-definitions/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 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.

97 changes: 97 additions & 0 deletions examples/using-type-definitions/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<!-- AUTO-GENERATED-CONTENT:START (STARTER) -->
<p align="center">
<a href="https://www.gatsbyjs.org">
<img alt="Gatsby" src="https://www.gatsbyjs.org/monogram.svg" width="60" />
</a>
</p>
<h1 align="center">
Gatsby's default starter
</h1>

Kick off your project with this default boilerplate. This starter ships with the main Gatsby configuration files you might need to get up and running blazing fast with the blazing fast app generator for React.

_Have another more specific idea? You may want to check out our vibrant collection of [official and community-created starters](https://www.gatsbyjs.org/docs/gatsby-starters/)._

## 🚀 Quick start

1. **Create a Gatsby site.**

Use the Gatsby CLI to create a new site, specifying the default starter.

```sh
# create a new Gatsby site using the default starter
npx gatsby new my-default-starter https://github.com/gatsbyjs/gatsby-starter-default
stefanprobst marked this conversation as resolved.
Show resolved Hide resolved
```

1. **Start developing.**

Navigate into your new site’s directory and start it up.

```sh
cd my-default-starter/
gatsby develop
```

1. **Open the source code and start editing!**

Your site is now running at `http://localhost:8000`!

_Note: You'll also see a second link: _`http://localhost:8000/___graphql`_. This is a tool you can use to experiment with querying your data. Learn more about using this tool in the [Gatsby tutorial](https://www.gatsbyjs.org/tutorial/part-five/#introducing-graphiql)._

Open the `my-default-starter` directory in your code editor of choice and edit `src/pages/index.js`. Save your changes and the browser will update in real time!

## 🧐 What's inside?

A quick look at the top-level files and directories you'll see in a Gatsby project.

.
├── node_modules
├── src
├── .gitignore
├── .prettierrc
├── gatsby-browser.js
├── gatsby-config.js
├── gatsby-node.js
├── gatsby-ssr.js
├── LICENSE
├── package-lock.json
├── package.json
└── README.md

1. **`/node_modules`**: This directory contains all of the modules of code that your project depends on (npm packages) are automatically installed.

2. **`/src`**: This directory will contain all of the code related to what you will see on the front-end of your site (what you see in the browser) such as your site header or a page template. `src` is a convention for “source code”.

3. **`.gitignore`**: This file tells git which files it should not track / not maintain a version history for.

4. **`.prettierrc`**: This is a configuration file for [Prettier](https://prettier.io/). Prettier is a tool to help keep the formatting of your code consistent.

5. **`gatsby-browser.js`**: This file is where Gatsby expects to find any usage of the [Gatsby browser APIs](https://www.gatsbyjs.org/docs/browser-apis/) (if any). These allow customization/extension of default Gatsby settings affecting the browser.

6. **`gatsby-config.js`**: This is the main configuration file for a Gatsby site. This is where you can specify information about your site (metadata) like the site title and description, which Gatsby plugins you’d like to include, etc. (Check out the [config docs](https://www.gatsbyjs.org/docs/gatsby-config/) for more detail).

7. **`gatsby-node.js`**: This file is where Gatsby expects to find any usage of the [Gatsby Node APIs](https://www.gatsbyjs.org/docs/node-apis/) (if any). These allow customization/extension of default Gatsby settings affecting pieces of the site build process.

8. **`gatsby-ssr.js`**: This file is where Gatsby expects to find any usage of the [Gatsby server-side rendering APIs](https://www.gatsbyjs.org/docs/ssr-apis/) (if any). These allow customization of default Gatsby settings affecting server-side rendering.

9. **`LICENSE`**: Gatsby is licensed under the MIT license.

10. **`package-lock.json`** (See `package.json` below, first). This is an automatically generated file based on the exact versions of your npm dependencies that were installed for your project. **(You won’t change this file directly).**

11. **`package.json`**: A manifest file for Node.js projects, which includes things like metadata (the project’s name, author, etc). This manifest is how npm knows which packages to install for your project.

12. **`README.md`**: A text file containing useful reference information about your project.

## 🎓 Learning Gatsby

Looking for more guidance? Full documentation for Gatsby lives [on the website](https://www.gatsbyjs.org/). Here are some places to start:

- **For most developers, we recommend starting with our [in-depth tutorial for creating a site with Gatsby](https://www.gatsbyjs.org/tutorial/).** It starts with zero assumptions about your level of ability and walks through every step of the process.

- **To dive straight into code samples, head [to our documentation](https://www.gatsbyjs.org/docs/).** In particular, check out the _Guides_, _API Reference_, and _Advanced Tutorials_ sections in the sidebar.

## 💫 Deploy

[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start/deploy?repository=https://github.com/gatsbyjs/gatsby-starter-default)

<!-- AUTO-GENERATED-CONTENT:END -->
35 changes: 35 additions & 0 deletions examples/using-type-definitions/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module.exports = {
siteMetadata: {
title: `Gatsby Default Starter`,
description: `Kick off your next, great Gatsby project with this default starter. This barebones starter ships with the main Gatsby configuration files you might need.`,
author: `@gatsbyjs`,
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `./src/images`,
},
},
`gatsby-transformer-sharp`,
`gatsby-plugin-sharp`,
`gatsby-transformer-json`,
{
resolve: `gatsby-source-filesystem`,
options: {
name: `data`,
path: `./src/data/`,
},
},
{
resolve: `gatsby-source-graphql`,
options: {
fieldName: `cms`,
url: `https://api-euwest.graphcms.com/v1/cjjr1at6d0xb801c3scjrm0l0/master`,
typeName: `GraphCMS`,
refetchInterval: 60,
},
},
],
}
82 changes: 82 additions & 0 deletions examples/using-type-definitions/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
exports.addTypeDefs = ({ addTypeDefs }) => {
stefanprobst marked this conversation as resolved.
Show resolved Hide resolved
const typeDefs = `
type AuthorJson implements Node {
name: String!
email: String!
picture: File @link(by: "relativePath")
posts: [BlogJson] @link(by: "authors.email", from: "email")
}

type BlogJson implements Node {
title: String!
authors: [AuthorJson] @link(by: "email")
text: String
date: Date @dateformat(formatString: "yyyy/MM/dd")
tags: [String]
}
`
addTypeDefs(typeDefs)
}

exports.addResolvers = ({
addResolvers,
actions,
cache,
store,
createNodeId,
// createContentDigest,
// reporter,
// getNode,
// getNodeAndSavePathDependency,
// pathPrefix,
}) => {
const { createRemoteFileNode } = require(`gatsby-source-filesystem`)
const { createNode } = actions
const resolvers = {
GraphCMS_BlogPost: {
// Wrap the resolver on an existing field by providing a function.
// The original resolver is available on `info.resolver`.
// This approach works fine if the returnType stays the same.
post: async (source, args, context, info) => {
const remark = require(`remark`)
const html = require(`remark-html`)
const result = await info.resolver(source, args, context, info)
// return a Promise with the markdown string converted to html
return remark()
.use(html)
.process(result)
},
},
GraphCMS_Asset: {
// Instead of a resolve function it is possible to provide a
// field config for a *new* field.
// This allows specifying a return type. The values of sibling fields
// are available from `source` if they are in the selection set.
// Be aware that without other fields in the selection set this will
// throw if the parent is NonNull, even if this resolver returns a value.
// This is because the delegated schema does not know about this field.
imageFile: {
type: `File`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nifty! So this will "just work" with the existing data layer e.g. you'll be able to transform images now w/ gatsby-transformer-sharp?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@KyleAMathews Yes you'll get a childImageSharp field for free, so it will just work. Note however, that the details may change a bit, what's reflected in the using-type-defs example is still my prototype. E.g. @freiksenet has suggested using fragments not projection.

// Projection fields will be included in the selection set without
// having to be explicitly added to the query, i.e.
// they will be accessible from `source`.
projection: { url: true, fileName: true },
resolve: async (source, args, context, info) => {
const { fileName, url } = source
const ext = `.` + fileName.match(/[^.]*$/)
const node = await createRemoteFileNode({
url,
store,
cache,
createNode,
createNodeId,
ext,
// name: fileName, // Needs #11054
})
return node
},
},
},
}
addResolvers(resolvers)
}
42 changes: 42 additions & 0 deletions examples/using-type-definitions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "gatsby-starter-default",
"private": true,
"description": "A simple starter to get up and developing quickly with Gatsby",
"version": "0.1.0",
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
"dependencies": {
"gatsby": "^2.0.55",
"gatsby-image": "^2.0.20",
"gatsby-plugin-sharp": "^2.0.14",
"gatsby-source-filesystem": "^2.0.13",
"gatsby-source-graphql": "^2.0.0",
"gatsby-transformer-json": "^2.1.7",
"gatsby-transformer-sharp": "^2.1.8",
"graphql": "0.13.2",
"prop-types": "^15.6.2",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"react-helmet": "^5.2.0"
},
"keywords": [
"gatsby"
],
"license": "MIT",
"scripts": {
"build": "gatsby build",
"develop": "gatsby develop",
"start": "npm run develop",
"format": "prettier --write \"src/**/*.js\"",
"test": "echo \"Write tests! -> https://gatsby.app/unit-testing\""
},
"devDependencies": {
"prettier": "^1.15.2"
},
"repository": {
"type": "git",
"url": "https://github.com/gatsbyjs/gatsby-starter-default"
},
"bugs": {
"url": "https://github.com/gatsbyjs/gatsby/issues"
}
}
Loading