sanity-io / image-url

Tools to generate image urls from Sanity content
https://www.sanity.io/docs/presenting-images#mY9Be3Ph
MIT License
67 stars 23 forks source link

how to use without a sanity client (for example, with gatsby-source-sanity) #2

Closed dylanjha closed 4 years ago

dylanjha commented 5 years ago

When using gatsby-source-sanity, I don't typically have access to a sanityClient directly, but I do have access to a sanity image asset object via the graphql api that the gatsby-source-sanity exposes.

The builder in this example requires a configured sanity client, is there a way to get the convenience of using the builder methods, by passing in a raw sanity asset that was obtained in a gatsby build?

const builder = imageUrlBuilder(myConfiguredSanityClient)
rexxars commented 4 years ago

You can use imageUrlBuilder({projectId: 'abc123', dataset: 'someDataset'}) if you know the project ID and dataset up front.

I suppose you could also extract the project ID and dataset from an asset by looking at the path property and doing some parsing, but that only works if the asset is the document and won't work if it's a reference

dylanjha commented 4 years ago

sweet, thank you!