Adding a non-REST data resource

I want to use a JSON-based graph database as a custom data resource.
It is also accessed thru javascript in a pub/sub mode vs. via REST calls.

How would I add this to the Data resources?
Or would it be added thru the custom JS in the component flows?

That would seem redundant vs. adding it as a custom data resource and then performing CRUD operations via JS in the relevant component flow.

1 Like

Technically you could use the REST resources for anything that inputs and outputs JSON in the correct format.

Say you needed to POST some JSON to an endpoint. You could setup a (REST) data resource and use the Create record flow to perform the request.

Get collection -> GET, expects array
Get one -> GET, expects object
Create record -> POST, expects object
(Update record -> PUT)
(Delete record -> DELETE)

The naming does get slightly confusing as the flows are aimed towards RESTful resources, but if your input and return types are compatible, you can keep the benefits of using the data resource configurator.

If your return types do not match the expected ones, you should make your own subflows using HTTP request flow.

Thanks for your reply but I probably wasn’t clear. The data resource I want to use does not have REST endpoints. CRUD operations are via javascript.

My question was two-fold:

How to add/define such a custom data resource at the project level.
I understand what you said about using a REST resource anyway … but it’s not clear to me HOW to do so in the dialogues provided since there are no such API endpoints? In fact, there’s no API in the typical sense. CRUD is carried out thru “parameterized” javascript.

It’s probably easier to watch this brief example vs. my garbled description:

The second question was how and where to “house” the CRUD statements once the data resource is added.

Sounds like that will be in the create record flows.

Thanks for your help!

Ah, after looking up GUN I think I understand what you are after. So there is no API, only an SDK. The first step in the documentation is:

  1. Add the GUN library.

We are working on a way to add your own plugins and libraries, but right now there is no supported way of adding those to your app. You could probably hack your way around this for the javascript library (by manually fetching it and adding it to the global object using javascript), but not for the React Native plugin.

If you could add the SDK (or hack it in), it’d be easiest to write your own subflows utilising the JS node. You could define a data resource + schema manually, but you would still have to add your custom logic for each instance where you’re using that resource.

Thanks for taking a look and for your reply.

Can you tell me more about hacking into the global object? Specifically, maually fetching it how?

Thanks!

Disclaimer: this gets pretty advanced, requires writing code, and 100% not officially supported in any way, so no guarantees this will keep working in future releases. My knowledge of GUN and its requirements are also limited to a brief glance of the docs.

You’d start by loading the library using a Javascript node. Unfortunately dynamic imports are relatively new, and don’t (yet) work on mobile. The following uses eval, but does work on both web and mobile:

if (!self.gun) {
  const response = await fetch('https://cdn.jsdelivr.net/npm/gun/gun.min.js');
  const js = await response.text();  
  
  self.eval(js); // stupidly dangerous and not recommended if you can avoid it
  
  self.gun = Gun();
  console.log('GUN loaded');
}

return {};

For most cases, you’d probably want to do this on the global canvas in app launch.

You can then register handlers in another JS node afterwards:

const { gun } = self;

// you should ensure handlers are registered only once
gun.get('random').on((data, key) => {
  console.log(`Random: ${data.value}`);
});

return {};

And finally you can insert values in yet another JS node, say attached to a button tap event:

const { gun } = self;
gun.get('random').put({ value: Math.random() });

return {};

You’d continue from here by creating your own GUN CRUD flows, which you could then use in your app like the core Get / Create / Update / Delete Record flows. And perhaps abstracting the handlers if it makes sense to do so.

1 Like

Wow! Thanks for such a detailed reply and solution.

I had figured the specific CRUD flows would be thru JS nodes … but didn’t even really know about the global canvas, being brand new to Appgyver.

This is the BEST tech support I’ve seen in literally decades.

I’ll be giving this a try ASAP.

Thanks very much!

1 Like

Love it :rofl: :rofl: :rofl: :rofl:

@James_Moses were you able to get it to work?

Thanks for checking. I got delayed by family and personal illness and am just now getting back to an attempt today and tomorrow.

SInce gundb is “controlled” via JS, I think I can set up database access thru an app variable and then create my own CRUD actions via javascript flow function per page and per field on page.

I’m going to try that approach with a simple todo app when I figure it out. :-p

I have a different question, if you don’t mind…?

I setup a scrolling vertical list of items on one page … and a vertically scrolling list of rows which contain a horizontally scrolling list of items on another page.

All works fine in the Appgyver preview app on my phone with the exception that the vertically scrolling list does not scroll thru ALL items set in Composer.

The horizontally scrolling items seem to be complete.

(These are not set dynamically).

However, after building a webapp and opening it on my Samsung phone, the vertical scroll affects the whole page instead of just the Vertically scrolling lists on both pages.

The horizontal scroll works fine in the built version in my phone.

I did turn off scrolling at the page level in Composer for both pages.

Is this a known bug … or a limit on webapps on phones?

IN either case, is there a way to fix it?

Thanks!

I’ll update you on my gundb attempts in a couple of days.

Oh, I just you’re not an Appgyver team member. Oops.

I’m seeing this via email and didn’t notice the details of your address.

No worries James! :slight_smile:

I was hoping you had some success as there are a number of SDKs I’d like to look into integrating. Unsure of the AG team’s timelines for implementing 3rd party plugins which will be a big game changer or if I could hack this together quickly for testing.

Well, my gundb attempt may not be all that helpful as it is pretty unusual in using simple JS to run all functions of the json graph database.

BUt I’ll let you know and share the sample app if i get it working.

I think (if I understand the issue here correctly) this should be doable also on web. It’s just that sometimes web needs you to more strict about limiting the Scroll view sizes. In most cases adding the Scroll view into a Container that is somehow limited to stay within certain has helped me.

Most cases when Scroll view is “too big” or shows just a part of the items means that the Scroll view actually stretches out of the boundaries it should have. So finding a way to limit the Scroll view size is likely the key. But, without knowing the specifics of this case, it’s hard to say how the configuration should be done here.

Thanks! I answered on the other, more specific thread and will try your suggestion today.