I noticed that the LocalTime type in the schema.graphql file for Shopify Functions is designed primarily for comparing given times and dates. However, it does not include a direct field or method to retrieve the current time.
This limitation poses challenges in scenarios where real-time operations or validations depend on the current time. Adding a new field to the LocalTime type to fetch the current time directly would greatly enhance functionality and simplify use cases like time-based logic in custom Shopify Functions.
I’ve connected with our product team on this and it appears that this limitation is intentional. All inputs must be provided to the function - it cannot pull anything from its environment, such as the current time, as this would mean that the same input could produce different outputs.
@NickWesselman : resolution to the current second would be nice; but i could also live with minute. the current ability to be able to query if the current time is after a specific date/time based on the static graphql query seems…not super useful, seeing as the graphql queries can’t be generated dynamically.
access to the current unix epoch timestamp would be great.
Hi @nickwesselman,
We have a similar requirement, our discount functions (rust) need the current timestamp. Minute precision is fine. It could be UTC or shop local time as long as its clear which one it is. UTC preferred.
Each of our Functions evaluates multiple discounts with relative priorities and , so we cannot split them across separate Function instances. These discounts also have individual start and end dates and some are potentially recurring.
Using localTime queries would likely exceed the Function input query size limit, since we would need a separate comparison for each date range, in addition to the other inputs our Function requires.
A single current timestamp with minute level precision would cover all our use cases.