How to use @sanity/schema - 7 common examples

To help you get started, we’ve selected a few @sanity/schema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / form-builder / examples / schema-testbed / components / SchemaForm.js View on Github external
import MyCustomValidationList from './custom/MyCustomValidationList'
import MyCustomImageInput from './custom/MyCustomImageInput'
import MyCustomFileInput from './custom/MyCustomFileInput'
import MyCustomSlugInput from './custom/MyCustomSlugInput'
import applyPatch from '../../../src/simplePatch'
import resolveReferenceInput from './custom/resolveReferenceInput'
import {arrayToJSONMatchPath} from '@sanity/mutator'
import InputWithCustomState from './custom/InputWithCustomState'
import {set, unset} from '../../../src/utils/patches'
import {resolvePreviewComponent} from '../../../src/defaultConfig'

const SCHEMA_NAMES = Object.keys(sourceSchemas)
const params = parseParams(document.location.pathname)

const schema =
  params.schemaName && params.typeName && Schema.compile(sourceSchemas[params.schemaName])

const PERSISTKEY = `form-builder-value-${params.schemaName}-${params.typeName}`

const schemaType = schema && schema.get(params.typeName)

function logPatch(patch) {
  const {type, path, ...rest} = patch
  console.log(
    // eslint-disable-line no-console
    '%c%s%c %s =>',
    'color:#2097ac',
    type,
    'color:inherit',
    arrayToJSONMatchPath(path || []),
    rest
  )
github sanity-io / sanity / packages / @sanity / form-builder / examples / undo / Main.js View on Github external
import React from 'react'
import Undoable from './lib/Undoable'

import Schema from '@sanity/schema'
import {FormBuilder} from '../../src'
import applyPatch from '../../src/simplePatch'

const schema = Schema.compile({
  name: 'simple',
  types: [
    {
      name: 'book',
      type: 'object',
      fields: [
        {
          name: 'title',
          type: 'string',
          title: 'Book title'
        },
        {
          name: 'author',
          type: 'string',
          title: 'Name of author'
        },
github sanity-io / sanity / packages / @sanity / form-builder / examples / quickstart / Main.js View on Github external
import React from 'react'
import FormBuilder from '../../src'
import applyPatch from '../../src/simplePatch'
import Schema from '@sanity/schema'

const schema = Schema.compile({
  name: 'simple',
  types: [
    {
      name: 'book',
      type: 'object',
      fields: [
        {
          name: 'title',
          type: 'string',
          title: 'Book title'
        },
        {
          name: 'author',
          type: 'string',
          title: 'Name of author'
        },
github sanity-io / sanity / packages / @sanity / base / src / schema / createSchema.js View on Github external
assetSourceData,
      slug,
      geopoint,
      legacyRichDate,
      imageAsset,
      fileAsset,
      imageCrop,
      imageHotspot,
      imageMetadata,
      imageDimensions,
      imagePalette,
      imagePaletteSwatch
    ].filter(Boolean)
  }

  const compiled = Schema.compile({
    name: schemaDef.name,
    types
  })

  compiled._source = schemaDef
  compiled._validation = validation

  return inferValidation(compiled)
}
github sanity-io / sanity / packages / @sanity / core / src / actions / graphql / extractFromSanitySchema.js View on Github external
const {uniqBy, startCase} = require('lodash')
const generateHelpUrl = require('@sanity/generate-help-url')
const schemaCompiler = require('@sanity/schema')
const oneline = require('oneline')
const helpUrls = require('./helpUrls')
const SchemaError = require('./SchemaError')

const Schema = schemaCompiler.default || schemaCompiler
const skipTypes = ['document', 'reference']
const allowedJsonTypes = ['object', 'array']
const disallowedCustomizedMembers = ['object', 'array', 'image', 'file', 'block']
const scalars = ['string', 'number', 'boolean']

function getBaseType(baseSchema, typeName) {
  return Schema.compile({
    types: baseSchema._original.types.concat([
      {name: `__placeholder__`, type: typeName, options: {hotspot: true}}
    ])
  }).get('__placeholder__')
}

function getTypeName(str) {
  const name = startCase(str).replace(/\s+/g, '')
  return name === 'Number' ? 'Float' : name
github sanity-io / sanity / packages / @sanity / base / src / schema / createSchema.js View on Github external
module.exports = schemaDef => {
  const validated = validateSchema(schemaDef.types).getTypes()

  const validation = groupProblems(validated)
  const hasErrors = validation.some(group => group.problems.some(isError))

  let types = []
  if (!hasErrors) {
    types = [
      ...schemaDef.types,
      assetSourceData,
      slug,
      geopoint,
      legacyRichDate,
      imageAsset,
      fileAsset,
      imageCrop,
      imageHotspot,
      imageMetadata,
      imageDimensions,
github sanity-io / sanity / packages / @sanity / base / src / schema / createSchema.js View on Github external
module.exports = schemaDef => {
  const validated = validateSchema(schemaDef.types).getTypes()

  const validation = groupProblems(validated)
  const hasErrors = validation.some(group => group.problems.some(isError))

  let types = []
  if (!hasErrors) {
    types = [
      ...schemaDef.types,
      assetSourceData,
      slug,
      geopoint,
      legacyRichDate,
      imageAsset,
      fileAsset,
      imageCrop,
      imageHotspot,

@sanity/schema

## Terminology

MIT
Latest version published 6 days ago

Package Health Score

98 / 100
Full package analysis