Giter VIP home page Giter VIP logo

Comments (3)

sgulseth avatar sgulseth commented on July 21, 2024 2

No problem at all!

You are running into a similar problem, but with a different expression. It's not the type generator, but how we utilize babel to traverse your code and piece together the different javascript expressions to find the "final" query. I think we could add support for binary expressions as long as both sides resolves to a literal value. However, I don't think this is the case for you here? I assume you're using this to paginate? You could instead of using javascript parameter use groq parameters? https://www.sanity.io/docs/groq-parameters#

We also have a guide for doing more efficient pagination here, but it depends on your use case 🙂

from sanity.

sgulseth avatar sgulseth commented on July 21, 2024

Hi!

This is not a bug in typegen per se, but rather how we discover queries. Since your query references a variable that contains a conditional expression we are unable to determine it. We would need to create a matrix of different query node types, with your example it would be "easy" since both would be the same, but we would also need to handle cases where they weren't

I think in your case however, this should work:

const start = 0
const limit = start + 12

const order = `| order(_createdAt ${orderBy})`
const slice = `[${start}...${limit}]`

groq`*[_type == "document"]${order}${slice}`

from sanity.

filipjohnsen avatar filipjohnsen commented on July 21, 2024

Thanks for the response and the explanation, partly fixed the problem!

Ran into a different problem where TypeGen threw a BinaryExpression error, fixed it by first declaring the variable with a static value and then mutating it with the dynamic values.

let start = page;
start = (page - 1) * POST_PER_PAGE;

let limit = POST_PER_PAGE;
limit = POST_PER_PAGE + start;

Not sure if this is the intended behaviour or not, could be useful to have some docs around the various errors 😃 Completely understand that TypeGen is experimental feature, been really enjoying it so far!

from sanity.

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.