question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API and database access

See original GitHub issue

This is more like an ideological question rather than an issue in the current version.

What is the proposed way of creating a custom API endpoints? Is it just like this server.app.get('/api/doSomething', (req, res) => { for every endpoint that is required? Could there still be some server-side routing for such cases?

Is there a way to access Mongoose directly as earlier? So how to make more complicated database queries that custom APIs could require? I see that there are new adapters for different datasources but does this prevent using Mongoose directly?

It would be very nice to see TypeORM as the ORM layer but unfortunately it works best with TypeScript and might be therefore hard to integrate here. Although writing own adapters can be tricky and require lots of work.

There can be some answers already but these were my first questions after looking this new version which otherwise looks very promising.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
JedWatsoncommented, Apr 8, 2019

@ttsirkia some really good points / questions here, going to see if I can help clear a couple of them up.

Internal APIs

The internal GraphQL APIs that @jesstelford is talking about are best thought of as an ORM layer. They ideally replace the usual things you’d get from mongoose like find() and update(), with the benefit of being built on top of Keystone’s internal abstractions (including field type logic and rules)

There’s no strong link between supporting things at the schema level (including custom mutations) and making them publicly available, although we’re still working through some of the tasks required to make it possible to create additional limited GraphQL endpoints (at the moment, there is only one, this will change soon)

But more complex queries, especially containing Mongo aggregation pipeline, are not possible.

I’m not sure that this is true, it’s what I’d expect custom queries and mutations to enable.

Raw database access

To answer your original question, yes the underlying database communication layer will always be exposed by the list, as was the case in Keystone 4. We’re hoping to make it less important, but will never stand in the way - especially because, as you noted, people need access to advanced features like aggregations etc.

Server can still use GraphQL, Mongoose queries, raw SQL or whatever.

This is the idea.

It’ll also be important for people migrating projects from older versions of keystone, which relied on a lot of mongoose usage.

Access Control

Before running queries, there can be very fine-grained access control etc. and I don’t see that a generic framework can provide all the needed control for this.

Have you had a look at our access control spec? It’s quite deep, and I’d be interesting in collecting use-cases that it doesn’t cover because we’re investing quite a lot in this part of Keystone 5.

One that came up recently was context-aware permissions (i.e a user can access certain fields on a model through some interfaces, like a query of related items, but not others) which is pretty interesting, but I’m hoping we can solve that by making custom queries and mutations easy to implement at the schema level.

0reactions
ttsirkiacommented, Apr 9, 2019

The third one has the following meaning:

  • Search the trains which have been actually driven but are not running at the moment, which have been late more than the given limit and their departure time is between the given dates
  • Create a group based on train’s number and type, calculate the average delay and the number of days when the limit has been reached
  • Take only those groups which have at least three entries
  • Sort them by using count and average, descending order
  • Group them again so that the train type will be the key and add the individual trains to a list which belongs to this train type
  • Limit the groups so that there are only the top ten trains in each group
  • Sort the groups by the train type

Here is a picture:

kuva

Boxes are the train types, in each box there is a train number and how many times it has been late over the limit and what is the average delay.

There are so many aggregation pipeline stages and pipeline operators that I don’t see it very beneficial to implement all these to GraphQL. Therefore, I was asking that is there still a possibility to write these queries using Mongoose directly.

I’m not that familiar with GraphQL but I’m also wondering how easily you can make dynamical queries. I mean that you produce the query at runtime instead of having it ready in the code. As GraphQL is a string instead of nested objects (as in Mongoose), it requires at least a library to do that. Manipulating objects and arrays to construct the query is very simple and no injections can occur.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Access API — Dataverse.org
The Data Access API provides programmatic download access to the files stored in a Dataverse installation. More advanced features of the ...
Read more >
Database Access API - OpenACS
The Database Access API addresses the first three problems by: making use of database handles transparent. wrapping common database operations (including ...
Read more >
How does an API work with a database? - Quora
In other sense, API is the DB query which can be usable in any platform and is fast accessing way to the data.On...
Read more >
Database Access via RESTful API Using LightWave
Many database vendors now provide access to their databases using RESTful APIs. They include Oracle, and MS SQL Server, the two leading databases...
Read more >
How to Use an API: Just the Basics 2022 | TechnologyAdvice
APIs are useful for more than accessing information for data-driven decision-making. You can also build programs that run searches on the data ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found