How to use the @sanity/client function in @sanity/client

To help you get started, we’ve selected a few @sanity/client 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 / base / src / client / index.js View on Github external
import config from 'config:sanity'
import configureClient from 'part:@sanity/base/configure-client?'
import sanityClient from '@sanity/client'

const deprecationMessage = `[deprecation] The Sanity client is now exposed in CommonJS format.

For instance, change:
  \`const client = require('part:@sanity/base/client').default\`

To the following:
  \`const client = require('part:@sanity/base/client')\`
`

const fallbackConfig = {projectId: 'UNSPECIFIED', dataset: 'UNSPECIFIED'}
const apiConfig = {...fallbackConfig, ...config.api, withCredentials: true, useCdn: false}
const client = sanityClient(apiConfig)

const configuredClient = configureClient ? configureClient(sanityClient(apiConfig)) : client

// Warn when people use `.default`
Object.defineProperty(configuredClient, 'default', {
  get() {
    // eslint-disable-next-line no-console
    console.warn(deprecationMessage)
    return configuredClient
  }
})

// Expose as CJS to allow Node scripts to consume it without `.default`
// eslint-disable-next-line import/no-commonjs
module.exports = configuredClient
github sanity-io / sanity / packages / @sanity / base / src / client / index.js View on Github external
import sanityClient from '@sanity/client'

const deprecationMessage = `[deprecation] The Sanity client is now exposed in CommonJS format.

For instance, change:
  \`const client = require('part:@sanity/base/client').default\`

To the following:
  \`const client = require('part:@sanity/base/client')\`
`

const fallbackConfig = {projectId: 'UNSPECIFIED', dataset: 'UNSPECIFIED'}
const apiConfig = {...fallbackConfig, ...config.api, withCredentials: true, useCdn: false}
const client = sanityClient(apiConfig)

const configuredClient = configureClient ? configureClient(sanityClient(apiConfig)) : client

// Warn when people use `.default`
Object.defineProperty(configuredClient, 'default', {
  get() {
    // eslint-disable-next-line no-console
    console.warn(deprecationMessage)
    return configuredClient
  }
})

// Expose as CJS to allow Node scripts to consume it without `.default`
// eslint-disable-next-line import/no-commonjs
module.exports = configuredClient
github staccx / sanity-query-helper / src / sanityQueryHelper.js View on Github external
get client() {
    return sanityClient(this.sanityOptions)
  }
github sanity-io / sanity / packages / @sanity / core / src / actions / dataset / strengthenReferences.js View on Github external
export default async function strengthenReferences(options) {
  const {importId, dataset} = options
  const progress = options.progress || noop
  const timeout = 605000
  const concurrency = 10
  const client = sanityClient(Object.assign({}, options.client.config(), {dataset, timeout}))
  const getReferenceDoc = ({prevImportMapId}) =>
    client.fetch(importMapQuery, {importId, prevImportMapId}).then(docs => docs[0])

  let referenceDoc = await getReferenceDoc({prevImportMapId: 'none'})
  while (referenceDoc) {
    debug('Found refmap with ID %s, processing', referenceDoc._id)
    await promiseEach(referenceDoc.referenceMaps, unsetRefMapKeys, {concurrency})

    debug('Unset weak flag within %d documents', referenceDoc.referenceMaps.length)
    debug('Deleting refmap with ID %s', referenceDoc._id)
    await client.delete(referenceDoc._id)
    referenceDoc = await getReferenceDoc({prevImportMapId: referenceDoc._id})

    progress(referenceDoc.referenceMaps.length)
  }

@sanity/client

Client for retrieving, creating and patching data from Sanity.io

MIT
Latest version published 3 days ago

Package Health Score

89 / 100
Full package analysis