Sanity Library Reference Docs
    Preparing search index...
    • Creates a $.resources.<name> reference to a resource in the blueprint, for options that take any string, such as the env of a function. Options that point at a specific kind of resource, such as project or robotToken, take the resource itself instead.

      Without an attribute, the reference resolves to the main identifier of the resource when the blueprint is deployed: the ID of a project, the name of a dataset, role or permission, or the token of a robot token.

      Parameters

      • resource: ResourceRef

        The resource that a definer or a referencer returned

      • Optionalattribute: string

        The attribute of the resource to reference, for example token or resourceId

      Returns string

      The reference, for example $.resources.reader.token

      const robot = defineRobotToken({
      name: 'reader',
      memberships: [{project: 'my-project-id', roleNames: ['viewer']}],
      })

      defineDocumentFunction({
      name: 'sync',
      env: {READ_TOKEN: reference(robot, 'token')},
      })
      const dataset = referenceDataset({name: 'production', stack: 'shared'})

      defineDocumentFunction({
      name: 'sync',
      env: {DATASET_ID: reference(dataset, 'resourceId')},
      })