Skip to content

Commit b77309f

Browse files
runebbinoy14
andauthored
feat: support shared content (#269)
This PR introduces a pre-processing step scanning the gql schemas from Sanity for directives that indicate a field or type as a cross dataset reference. When these directives are found, the corresponding fields are manipulated to be treated as normal references with the expectation that the user will add another source config for the target dataset in the Gatsby app configuration. Through Gatsby schema composition the types should then match up, and the node resolution should also pick out the target documents. The main implementation to review is found in `packages/gatsby-source-sanity/src/util/mapCrossDatasetReferences.ts` End to end tests de-referencing both normal and cross dataset references from actual Sanity datasets are included in the `cdrs` Gatsby app in `examples`. To run tests, first make sure the test app is running ```bash cd examples/cdrs && rm -rf .cache public && npm run develop ``` Then run the test suite in that folder ```bash cd examples/cdrs && npm test ``` --------- Co-authored-by: Binoy Patel <me@binoy.io>
1 parent bd64f80 commit b77309f

27 files changed

+52746
-10315
lines changed

examples/cdrs/.gitignore

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# Compiled binary addons (http://nodejs.org/api/addons.html)
33+
build/Release
34+
35+
# Dependency directories
36+
node_modules/
37+
jspm_packages/
38+
39+
# Typescript v1 declaration files
40+
typings/
41+
42+
# Optional npm cache directory
43+
.npm
44+
45+
# Optional eslint cache
46+
.eslintcache
47+
48+
# Optional REPL history
49+
.node_repl_history
50+
51+
# Output of 'npm pack'
52+
*.tgz
53+
54+
# dotenv environment variable files
55+
.env*
56+
57+
# gatsby files
58+
.cache/
59+
public
60+
61+
# Mac files
62+
.DS_Store
63+
64+
# Yarn
65+
yarn-error.log
66+
.pnp/
67+
.pnp.js
68+
# Yarn Integrity file
69+
.yarn-integrity

examples/cdrs/.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.cache
2+
package.json
3+
package-lock.json
4+
public

examples/cdrs/.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"arrowParens": "avoid",
3+
"semi": false
4+
}

examples/cdrs/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
This is a test Gatsby app for end-to-end testing the gatsby-source-sanity plugin with Sanity Content Lake data and schema
2+
3+
# Testing
4+
Manually run the application
5+
6+
```bash
7+
rm -rf .cache public && npm run develop
8+
```
9+
10+
Run the test suite
11+
12+
```bash
13+
npm test
14+
```

examples/cdrs/gatsby-config.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/**
2+
* Configure your Gatsby site with this file.
3+
*
4+
* See: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/
5+
*/
6+
7+
const path = require("path")
8+
const pluginPath = path.resolve(
9+
__dirname,
10+
"../../packages/gatsby-source-sanity"
11+
)
12+
13+
/**
14+
* @type {import('gatsby').GatsbyConfig}
15+
*/
16+
module.exports = {
17+
siteMetadata: {
18+
title: `Gatsby Default Starter`,
19+
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.`,
20+
author: `@gatsbyjs`,
21+
siteUrl: `https://gatsbystarterdefaultsource.gatsbyjs.io/`,
22+
},
23+
plugins: [
24+
{
25+
resolve: pluginPath,
26+
options: {
27+
apiHost: "https://api.sanity.work",
28+
projectId: "rz9j51w2",
29+
dataset: "production",
30+
},
31+
},
32+
{
33+
resolve: pluginPath,
34+
options: {
35+
apiHost: "https://api.sanity.work",
36+
projectId: "rz9j51w2",
37+
dataset: "shared",
38+
},
39+
},
40+
`gatsby-plugin-image`,
41+
],
42+
}

0 commit comments

Comments
 (0)