-
Notifications
You must be signed in to change notification settings - Fork 37
link resolution + json serialization #10
Comments
Ok, so I'll start trying describe the current state of this package. As you have correctly guessed, our (JS and Ruby) clients have two different ways of interacting with DatoCMS API. The first ( import { SiteClient } from 'datocms-client';
const client = new SiteClient("YOUR-API-KEY");
const article = await client.items.create({ itemType: "44", content: "Lorem ipsum dolor sit amet..." }); The second one ( import { SiteClient, Loader } from 'datocms-client';
const client = new SiteClient("YOUR-API-KEY");
const loader = new Loader(client);
await loader.load();
loader.itemsRepo.articles[0].author.avatarImage.url(); While this |
Now, if the need is to find a good way of integrating DatoCMS with Spike, I would suggest you not trying to reinvent the wheel and directly offer to your users an I'll copy the conversation here:
|
@stefanoverna awesome, thanks for providing more info about the As for spike + dato, I guess I should say that I was not explicitly filing this issue to support spike-dato, I was just using it as a known reference. At the moment, I'm actually doing a non-spike implementation which was why link-resolution was so important to me bc I didn't have the link resolution available to me thats part of spike-dato. Anyways, I'll do a bit more digging on how the Loader can be used now that, in lieu of some docs, you've cleared up the basics. |
Ok, let me know if you got everything you need :) |
@stefanoverna do these functions create another network call to the API or just traverse the object from the original API response? |
Only two API calls gets made during the |
Just to make clear: here we try to keep things simple and manageable, and for our initial use case (static websites) the current solution — that is, having a limited API, fetch everything during the build phase and then offer a handy interface for querying with the This obviously doesn't work as well when you simply cannot afford to download everything (ie. client-side apps, server-side apps, mobile apps, etc). We've in the roadmap to add read-only GraphQL API with advanced querying functionality for that in the near future, but for now.. that's what we offer :P |
yup, understood. i personally like the big API response bc it lets me cache my data locally easily but obviously it limits folks with huge datasets or client-side requirements. thanks for sharing roadmap info, stefano |
two points but i think they are fairly interconnected so i've only filed one issue.
link resolution
it appears that there is partial support for this in the library but it's not documented. since all of your site's json gets returned from one API call this shouldn't be hard to do either. are you open to the idea of adding an option that would do nested resolution from within this client so that we don't have to traverse our objects for each implementation of the client? ideally this would look like contentful.js' option but could also be part of .get() or .all() functions. in practice all anyone ever wants is their fully resolved data so i could even imagine this option is
true
by default.json serialization
while looking for this link resolution functionality i came across
src/local/Loader.js
which I think does link resolution but returns a class object with no ability to serialize this to json. the assumption here is so that it would avoid circular references that might happen if it were json. as part of thelink resolution
request, it makes sense that some kind of smart json serialization that avoids the infinite loops.this seems like an extremely common use case and we've avoided filing this issue in the past because we've done our own link resolution within our
spike-datocms
plugin, but imo this really should be handled by the clientcc @jescalan
The text was updated successfully, but these errors were encountered: