Skip to content

Commit

Permalink
feat: support shared content (#269)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
runeb and binoy14 authored Oct 17, 2023
1 parent bd64f80 commit b77309f
Show file tree
Hide file tree
Showing 27 changed files with 52,746 additions and 10,315 deletions.
69 changes: 69 additions & 0 deletions examples/cdrs/.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 variable files
.env*

# gatsby files
.cache/
public

# Mac files
.DS_Store

# Yarn
yarn-error.log
.pnp/
.pnp.js
# Yarn Integrity file
.yarn-integrity
4 changes: 4 additions & 0 deletions examples/cdrs/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cache
package.json
package-lock.json
public
4 changes: 4 additions & 0 deletions examples/cdrs/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"arrowParens": "avoid",
"semi": false
}
14 changes: 14 additions & 0 deletions examples/cdrs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
This is a test Gatsby app for end-to-end testing the gatsby-source-sanity plugin with Sanity Content Lake data and schema

# Testing
Manually run the application

```bash
rm -rf .cache public && npm run develop
```

Run the test suite

```bash
npm test
```
42 changes: 42 additions & 0 deletions examples/cdrs/gatsby-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Configure your Gatsby site with this file.
*
* See: https://www.gatsbyjs.com/docs/reference/config-files/gatsby-config/
*/

const path = require("path")
const pluginPath = path.resolve(
__dirname,
"../../packages/gatsby-source-sanity"
)

/**
* @type {import('gatsby').GatsbyConfig}
*/
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`,
siteUrl: `https://gatsbystarterdefaultsource.gatsbyjs.io/`,
},
plugins: [
{
resolve: pluginPath,
options: {
apiHost: "https://api.sanity.work",
projectId: "rz9j51w2",
dataset: "production",
},
},
{
resolve: pluginPath,
options: {
apiHost: "https://api.sanity.work",
projectId: "rz9j51w2",
dataset: "shared",
},
},
`gatsby-plugin-image`,
],
}
Loading

0 comments on commit b77309f

Please sign in to comment.