liontariai / samarium

https://liontari.ai/
Apache License 2.0
9 stars 0 forks source link

Issue on website code snippet #16

Open schettn opened 1 week ago

schettn commented 1 week ago

I just saw this on your website and haven't tested it but I think the ...fields (autocompletion support) cannot work as fields isn't defined anywhere.

import spacex from "spacex";

const { company } = await spacex((op) =>
    op.query((q) => ({
        company: q.company(
            ({
                name,
                ceo,
                founded,
                ...fields // 👈 Autocompletion support
            }) => ({
                name,
                ceo,
                founded, //
            })
        ),
    }))
);
schettn commented 1 week ago

Ah.. while writing this issue I realised that ..fields is simply a placeholder and you want to communicate that the user can type any field via autocomplete.

This is maybe a bit confusing.

liontariai commented 1 week ago

Yep. Good point... that was the intention. At the same time, '...fields' is a 'Rest' operator and so at least the 'fields' object/var now contains the rest of the fields, i.e. all fields except 'name', 'ceo' and 'founded'.

Maybe I'll come up with a better illustration, thanks for the heads-up!

schettn commented 1 week ago

I thought in term of gqty.. But there is a major difference. You use callbacks for nested queries (I missed that). Qqty uses return objects which are then analysed via a Proxy.

const {company} = await resolve(({Query}) => {
  const company = Query.company(...args)

  return {
    name: company.name,
    ceo: company.ceo,
    founded: company.founded
  }
})

Do you support args?

schettn commented 1 week ago

Nvm. Just found it:

image

schettn commented 1 week ago

You should really link the Playground on you website.

liontariai commented 1 week ago

Yes, you can use args everywhere and they are hoisted into the variables of the graphql operation. You can even use the same field (which needs args) multiple times via an alias, and the args/vars will be matched to the right instance. Even works if you use args in fragments :)

See https://github.com/liontariai/samarium/pull/6

grafik

liontariai commented 1 week ago

You should really link the Playground on you website.

yea the playground website was my first try... the liontari.ai website is my try to look more 'professional' :D I should kinda merge both somehow, you're right. Or at least link it, true.. I'll do that first I guess.