Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
gridsome-source-sanity
Advanced tools
Readme
Sanity.io source for Gridsome. Requires Gridsome 0.7.1 or above.
npm install gridsome-source-sanity
# or
yarn add gridsome-source-sanity
This source plugin only works if you publish a GraphQL API for your project and dataset. It will use the GraphQL API’s schema definitions to set the proper fields for your schema types.
~/yourSanityProjectFolder > sanity graphql deploy
Remember to redeploy the GraphQL API when you have changed the schema for Sanity.
module.exports = {
plugins: [
{
use: 'gridsome-source-sanity',
options: {
projectId: '<projectId>',
dataset: '<datasetName>',
// Token is only required if dataset is private
// or `overlayDrafts` is set to true
token: '<tokenWithReadRights>',
overlayDrafts: false,
// Only enable real-time changes in development
watchMode: process.env.NODE_ENV === "development",
// API Version has to be set to today's date for the latest features.
// See: https://sanity.io/help/js-client-api-version
apiVersion: '2021-10-14',
// If the Sanity GraphQL API was deployed using `--tag <name>`,
// use `graphqlTag` to specify the tag name. Defaults to `default`.
graphqlTag: 'default'
}
}
]
}
Options | Type | Default | Description |
---|---|---|---|
projectId | string | [required] Your Sanity project's ID | |
dataset | string | [required] The dataset to fetch from | |
token | string | Authentication token for fetching data from private datasets, or when using overlayDrafts Learn more | |
graphqlTag | string | default | If the Sanity GraphQL API was deployed using --tag <name> , use this to specify the tag name. |
overlayDrafts | boolean | false | Set to true in order for drafts to replace their published version. By default, drafts will be skipped. |
watchMode | boolean | false | Set to true to keep a listener open and update with the latest changes in realtime. If you enable overlayDrafts , changes will be reflected almost down to each keypress. This option shouldn't be enabled during build or else the listener will prevent it from being completed. |
typeName | string | Sanity | Prefix for schema types and queries. |
Sometimes you might be working on some new content that is not yet published, which you want to make sure looks alright within your Gridsome site. By setting the overlayDrafts
setting to true
, the draft versions will as the option says "overlay" the regular document. In terms of Gridsome nodes, it will replace the published document with the draft.
Keep in mind that drafts do not have to conform to any validation rules, so your frontend will usually want to double-check all nested properties before attempting to use them.
Certain fields (portable text fields being one of them) will get a "raw JSON" representation in a field called _raw<FieldName>
. For instance, a field named body
will be mapped to _rawBody
. This is a workaround for a known GraphQL introspection shortcoming that will be addressed in a future version of Sanity.
Quite often, you'll want to replace reference fields (eg _ref: '<documentId>'
), with the actual document that is referenced. This is done automatically for regular fields, but within raw fields, you have to explicitly enable this behavior, by using the field-level resolveReferences
argument:
{
allSanityProject {
edges {
node {
_rawTasks(resolveReferences: {maxDepth: 5})
}
}
}
}
Rich text in Sanity is usually represented as Portable Text (previously known as "Block Content").
These data structures can be deep and a chore to query (specifying all the possible fields). As noted above, there is a "raw" alternative available for these fields which is usually what you'll want to use.
You can install sanity-blocks-vue-component from npm and use it in your Gridsome project to serialize Portable Text. It lets you use your own Vue components to override defaults and render custom content types. Learn more about Portable Text in our documentation.
FAQs
Sanity.io source for Gridsome
The npm package gridsome-source-sanity receives a total of 119 weekly downloads. As such, gridsome-source-sanity popularity was classified as not popular.
We found that gridsome-source-sanity demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 26 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.