GraphQL interface for Core and Horizon databases
- Edited
Hey Tyler this is absolutely beautiful! Forgive my ignorance about GraphQL but where can we get a list of all entities/fields in order to build some queries? This stuff is amazing!
* facepalm * Top/right there is a Docs link
Torkus Best place is just to explore the "Docs" -> "Query" on the graphiql page itself.
And then too for some inspiration you can read https://medium.com/@tyvdh/fair-enough-6da46b0734aa
- Edited
Thanks, I'm in love!
Hey quick question, can we submit queries using plain http POST? Is there any API endpoint for that? I played with the web UI which is cool but I'd like to make a query once in a while from a program to check for trustlines which is something StellarSDKs lack and it is in urgent need the more tokens get created. Someday when I grow up I'll get my own node and your posts are perfect guides for that but for now I'd be more than happy to hit your service once a day while I get used to server stuff.
* To expand, I saw the links to https://api-test.gly.sh and https://api.gly.sh but do they get graphiql queries in the post body so we get the same responses as the web UI? The ones I tried are just proxies to horizon responses which is not what I want.
Torkus You certainly can! Projects like Apollo https://www.apollographql.com/ make it a lot easier but if you inspect the console on the graphiql page you can see the HTTP requests going out.
Another * facepalm * haha so obvious, the web UI has to communicate with the server duh! I'll take a look, thanks!
This is related to the question posed on stackexchange here: https://stellar.stackexchange.com/questions/729/possible-to-get-a-list-of-account-holders-satisfying-certain-criteria-using-hori/730
If I want a complete list of all native (xlm) accounts that meet a certain criteria, but have the results not just show on my browser but instead get fed into a db, is there a way to take the output from graphiql and get it into a database (there could be 1000's of accounts)? I don't want to overload your setup...
The other option is the one I see mentioned on the above post's answers: setup an instance of stellar core and query the database, and then use that info to build my own database. Is that the only real option here or are there other alternatives?
- Edited
This is a great project! I totally overlooked it back then.
I'm currently reaching the limits of Horizon with https://equilibre.io. For some portfolios it has keep 20 or more orderbooks up to date, plus the list of offers, and it's badly lagging. It is pretty clear that a GraphQL solution with compound data & subscription could largely improve this situation.
It looks likes what you released so far is a sort of sophisticated demo (no orderbook support for example). Have you any plan implementing in completely?
I have a few questions about GraphQL:
- Could it fully replace Horizon?
- How does it compare cost-wise with a RESTful solution?
- Any way to guard against "abusive" requests?
- Edited
MisterTicot Hey, there! Appreciate the comments and questions.
To answer the questions in short:
- Yes, GraphQL could fully replace all existing Horizon functionality, and it wouldn't be too much work either. Would basically just need to add streaming support and mutation functionality back in.
- Cost wouldn't be much different from an operating standpoint, you do have another service to standup and if you want custom functionality you'd have to build that in your self but if you're familiar with postgres or graphql it wouldn't take much time.
- Great question and yes, there are several ways abuse could be mitigated. There are several articles and tutorials on the subject. Here's a good one for example. https://blog.apollographql.com/securing-your-graphql-api-from-malicious-queries-16130a324a6b
As far as building these things out myself in gly.sh I'm doubtful. I'd really need to beef up my servers and add a lot of the support for things you've mentioned. While it wouldn't be terribly difficult or expensive, without a consistent Saas type business model it simply wouldn't make sense for me to provide a single solution for everyone. Better for everyone to host, run and customize their own instances at least until the concept of StellarQL matures and we get a better sense of what a single solution might look like as far as features and speed.
- Edited
MisterTicot Also unless I'm mistaken you can already get the orderbook from the core graphql endpoint with a request something like this.
query allOffers {
offers: allOffers(
first: 100
filter: {
or: [
{sellingassetcode: { equalTo: "WSD" }}
{buyingassetcode: { equalTo: "WSD" }}
]
}
) {
nodes {
lastmodified
sellingassettype
sellingassetcode
sellingissuer
buyingassettype
buyingassetcode
buyingissuer
}
}
}
That would return all offers buying or selling the asset code WSD
Thank you for the detailled answer. This is absolutely interesting. I think I'll dig in as soon as I can get myself some more free time.
Thank you as well for the offers query. I totally overlooked it.
- Edited
Pleased to announce I've recently launched fully synced production level endpoints for both the test and public networks. They can be reached at these new endpoints.
https://core.stellarql.com/graphql
https://horizon.stellarql.com/graphql
https://core-testnet.stellarql.com/graphql
https://horizon-testnet.stellarql.com/graphql
As of today I'm taking down the gly.sh endpoints.
Happy coding!
StellarQL is shutting down in favor of https://astrograph.io/. The folks over there are doing a better job at porting the Stellar database over to a GraphQL endpoint. Rather than have people choose, why not just choose the better service!
Thanks for all the support and feedback during the lifetime of the project. It was a great ride and I'm confident the folks over at Evil Martians will take the idea to places I could have only ever hoped.
Hi,
Could you give me the code to get alltrustline an asset
I tried with this code but it not work on https://pubnet.astrograph.io/
{allTrustlines(orderBy: [BALANCE_DESC], condition:{assetcode:"XRP", issuer:"GCNSGHUCG5VMGLT5RIYYZSO7VQULQKAJ62QA33DBC5PPBSO57LFWVV6P"}) {
nodes {
accountid
balance
assetcode
}}}
Thank you
- Edited
StellarUAE Hi! Here's how you would do it in Astrograph:
{
asset(id: "USDC-GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN") {
balances(first:10) {
nodes {
account { id }
spendableBalance
authorized
}
}
}
}
Astrograph was built from the ground up to be a fully-featured GraphQL server for Stellar network, rather than a thin wrapper around existing storages. A large part of the value of GraphQL lies in providing an abstraction between services and consumers, so the schema should not be tightly coupled either to particular service implementations or to particular consumers as they exist today. So in general don't expect Astrograph to directly expose Core/Horizon DB relational data.
You will notice here and there that we didn't limit ourselves by existing table structures or Horizon-defined representations of certain entities. Instead, we tried to follow schema-first approach and tried to map Stellar network on a graph in the most sensible way. For example, unlike stellar-core, in Astrograph asset is a proper top-level entity, and you can start with the asset and then follow the asset <1--*> balance
connection to get all the balances, and each balance belongs to an account, so you can follow that connection, and so on until you get all the necessary data. Also, in certain cases we took the liberty to use different terminology (i.e. trustline
vs balance
).
There's some basic schema documentation, but I would recommend to use interactive documentation and playground with autocomplete, which also has schema embedded docs.
One final note is that we don't provide any SLA for our pubnet and testnet Astrograph instances, so they should be considered development playgrounds and not used in anything close to live systems. In particular, pubnet instance does not have the full historical data ingested.
If you'll have further questions, feel free to start a discussion on Github or jump in to our public Keybase group