Git Product home page Git Product logo

Comments (4)

joeswann avatar joeswann commented on June 15, 2024

There is a reproduction of this issue at https://github.com/1of1studio/repro-sanity-codegen - the only customisation is to add an alias for a sanity ui component to no-op in order to get sanity-codegen to run.

Note: Will require a projectId in sanity.json to run sanity of course

from sanity-shopify-studio.

robinpyon avatar robinpyon commented on June 15, 2024

Hey @joeswann – thanks for the clear report and providing a repro here!

The documentation you've linked is correct! But it's worth pointing out that those naming restrictions apply specifically to field names and not document names.

For instance, if you try and create a field with the name alternate.name, Sanity will throw an error and the studio won't run at all. However, periods in document names are valid and these are used extensively throughout the studio (Sanity assets are documents named sanity.imageAsset and sanity.fileAsset)

I can't speak for sanity-codegen – it looks like it may be applying field name validation to document names as well, but it may have a good reason for doing so!

from sanity-shopify-studio.

joeswann avatar joeswann commented on June 15, 2024

Hi @robinpyon and thank you for the quick response!

That's a great clarification, I have a couple of follow up thoughts to cover then:

  • First - The documentation is a bit unclear on this because Sanity specifically states that documents are a kind of object, even going so far as to say Apart from the above, documents are defined just like regular objects, so see the documentation of the object type for more info about how to define documents.. This is a little loose though and it may not be intended to specifically include the field name validation, that idea would be bolstered if sanity uses sanity.fileAsset already.

  • Second, I think some of the objects actually do have a period in their field name, such as seo.singleton, seo.standard and seo.product - these do not appear to be documents? Could it be that they don't break Sanity due to their field name being different when actually applied (im not sure whether Sanity validates the source object name or only the destination when referencing the object type in schema?).

Codegen may only be trying to generate types for externally defined schema, which might be why it wasn't already an issue with sanity.fileAsset... Not sure on that one!

from sanity-shopify-studio.

robinpyon avatar robinpyon commented on June 15, 2024

No worries!

First - The documentation is a bit unclear on this because Sanity specifically states that documents are a kind of object ... [t]his is a little loose though and it may not be intended to specifically include the field name validation ...

I should have been clearer by instead saying "periods in object and document names are valid" instead. The docs are correct though – and the fields property on the document page does point to the fields section in the document page.

That said, I agree with you that this is a little unclear. Given that fields are shared across both documents and objects, perhaps there's an argument for abstracting that out into a separate page.

Second, I think some of the objects actually do have a period in their field name, such as seo.singleton, seo.standard and seo.product - these do not appear to be documents?

That's correct, these are infact objects which are referenced by other documents (or even other objects).

Im not sure whether Sanity validates the source object name or only the destination when referencing the object type in schema?).

Sanity will validate ALL object names at runtime (even if unreferenced) and will also throw errors when you try and reference an object that doesn't yet exist in your schema.

I'm going to close this as I don't believe this issue lies with this specific studio setup, but please feel free to continue the conversation here!

from sanity-shopify-studio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.