Fork me on GitHub
#xtdb
<
2021-12-13
>
craftybones14:12:17

Hello. I’m looking at Site. Can valid time be specified on requests?

alexdavis14:12:53

Yes, you can use the field _siteValidTime

alexdavis14:12:28

Worth mentioning the site is very alpha currently, I’m going to put up some better docs soon though

craftybones14:12:27

What is interesting is that I was recently thinking about the very same thing, except I thought it would be cool to have a tool that can generate an app based on a schema

alexdavis14:12:49

Generating UIs you mean?

craftybones14:12:05

Server code and UIs, yes

alexdavis14:12:25

There have been some attempts at that https://github.com/vazco/uniforms, but I’m not convinced its a good idea

alexdavis14:12:59

You can generate fetching logic for the frontend with this https://www.graphql-code-generator.com/. I am using it with react-query and it works great

craftybones14:12:03

I was talking more in the context of xtdb

alexdavis14:12:40

Right, thats what site is trying to do

alexdavis14:12:58

not really generating anything though

craftybones14:12:13

Well, best of luck. I’ll play around with it

alexdavis14:12:00

This code is in need of a refactor as we’re currently just prototyping, but you can see most of how the graphql schema gets turned into XTDB queries here https://github.com/juxt/site/blob/ba44b0241931c5f2e2228aae68006a858333bc65/src/juxt/site/alpha/graphql.clj#L634 (theres a big case statement to handle the various directives you can add to the schema, if none are added it will fall through to that ‘infer-query’ function. The ‘query’ function is called for every field in the graphql query, as per the graphql spec)

craftybones14:12:48

How do references work?

alexdavis14:12:51

you can add a ‘ref’ directive, which takes the name of the key you want to join on. see here for details https://github.com/juxt/site/blob/ba44b0241931c5f2e2228aae68006a858333bc65/src/juxt/site/alpha/graphql.clj#L479

alexdavis14:12:36

user: User! @site(ref: "userId") example usage

alexdavis14:12:37

if the given id exists on the current xt document, it will do an entity lookup on that, otherwise it will do a query for documents with a type matching the return type on the field, and an attribute matching the given ref value

alexdavis14:12:35

should probably keep this stuff in a thread, feel free to reply here if you want more help

🙏 1
🙂 1