Querying entities for all user created DBs

I would like to query all entities in my fibery account dynamically (without providing the DB names, but rather extracting them from the schema). For this, I need to understand from the schema which types are user generated DBs and which types are internal/ system types.

I noticed there are many metadata flags returned, some of them are:

  • “fibery/domain?”
  • “fibery/platform?”
  • “fibery/secured?”
  • “fibery/entity-component?”
  • “fibery/schema-only?”
  • “fibery/type-component?”
  • “fibery/enum?”

Is it possible to have a quick description of what each of these fields mean?
Also is there is any recommendation on how to “understand” from the schema which types are user generated DBs?

1 Like

If you filter on fibery/domain? == true then you will get all the databases in your spaces (+ the user db).

Out of interest, what is your end goal with querying all the entities?

Thank you for the prompt response!

We are creating an integration with Fibery, and want to query all entities generically in our system.

I have some follow up questions:

  1. You mentioned using the domain flag leaves you with the user DB as well- if I wanted to filter this without hardcoding the user db name, would you say that filtering on the “platform” flag (fibery/platform? == false && fibery/domain? == true) would be sufficient (to only retrieve the space DBs)?
  2. Is there any way to retrieve all the account’s space names, other than traversing the schema and filtering (in order to use with the GraphQL API that requires the space name as part of the URL path)?
  3. Is there a way to retrieve full rich text fields content using the REST API entities query (without having to separately GET each rich text field using the document endpoint)? If not - is the only way to retrieve all rich documents content in a single request - to use the GraphQL API?
  4. Is there a way to retrieve the total number of entities in a DB (asking both for REST and for GraphQL)?

Sounds interesting, would love to hear more.

Well, it would work. But the full typename for the user db fibery/user is not expected to change, so there’s no real advantage that I can think of.

Spaces are known as apps in the API terminology, and are in fact ‘entities’ of the type ‘fibery/app’, so this will work:


 "command": "fibery.entity/query",
    "args": {
        "query": {
            "q/from": "fibery/app",
            "q/select": ["fibery/name"],
            "q/where": ["=", ["fibery/show-in-menu?"], true],
            "q/limit": "q/no-limit"
        }
    }

Have a look here:
https://the.fibery.io/@public/User_Guide/Guide/Entity-API-264/anchor=Select-rich-text-Field--f9838a54-3d74-4f49-9f5d-9195731c7e89

specifically this:

Thank you so much, this is great info and very helpful!

2 more questions if that’s ok

  1. Is there a way to retrieve the total number of entities in a DB (asking both for REST and for GraphQL)?
  2. When trying to query graphQL for a space that has no DBs, I get a 500 error response with the following message: “There are no any databases for space [Getting Started]”. Introspection fails on this error. Is this a bug or the intended behaviour?

What is the nature of the query? I mean, why would you want to query a space that has no DBs?

I don’t believe it is possible, except by performing an unfiltered query and calculating the size of the returned array of entities.
What is the underlying need to know how many entities there are?

Our use case is roughly as follows:
We want to periodically query all user spaces for new entities (using GraphQL as it seems to fit our needs best), without assuming any prior knowledge of what spaces/ dbs exist.
When fetching all user spaces using your suggestion (using the entities query from apps), we also receive spaces that have no DBs (if they exist in the account).
Is there a way to know from metadata that a space has no DBs (so we can skip querying it)?

As for knowing the total number of entities- we’d like to track a percentage progress of our queries.

Thanks again, appreciate all the help!

If you want to query all dbs, then there is no need to query all spaces, is there? Just check for domain dbs and query them directly.

Sounds intriguing. Where is the data ending up?
If you can’t make assumptions ahead of time about the schema, I’m curious to know what the downstream activities might be.

Is this because you are keeping track of the total number of entities in a db, and then using this number to decide if new entities have been added?

Overall, it does sound like you might be better served by using webhooks, to get notified of changes, and then update/maintain your webhooks as needed if the Fibery schema changes.

Can you suggest how to do that using GraphQL? Each space has its own graphQL endpoint, and to construct a graphQL query, introspection needs to be available- but it fails for spaces without DBs.

I’d be happy to elaborate in PM.

We have looked at webhooks as an option, but it does not answer our requirements.

Why use GraphQL? The REST API is better for this sort of thing.

Feel free to message me here.

Because of the issue I mentioned with fetching rich text fields as part of the same query. If I were to use REST API- I would need to parse the response, take all the document secrets, and query for those using the endpoint you mentioned, making the solution more complex than GraphQL which returns rich text fields as part of the same query.

I meant that you could use the REST API to get the complete list of Databases (including which Space they belong to) and then use this info in any way you like (including GraphQL queries to get the entities)

I see, thank you. This is what I initially did and it does work well, but the suggestion you had here:

Is much cleaner and easier to maintain, but I understand that it is less appropriate for my use case. Thank you!

1 Like