Open sander1095 opened 3 months ago
I've created a reproducable repo here: https://github.com/sander1095/dab-graphql-csharp-client
@sander1095 thanks for raising the issue, we will check and get back!
where does the fix for this sit on the priority list please ? Or is there a less convoluted workaround. Thanks.
Since you're working with a NoSQL database where the schema can vary with each record, DAB is unable to predict the sub-entities present. Therefore, it is recommended to explicitly configure the entities you're interested in within the configuration. This will ensure that DAB generates the GraphQL API only for those specified entities.
Hi @sourabh1007 thank you for the technical explanation. I would however like to challenge, that from a usability point of view, it feels counter intuitive when notionally one has already provided a .gql
schema defining all child class/type sub-entities relationships.
Being required to define sub-entities in config feels like an unnecessary barrier to entry for using this fabulous dab tool.
What happened?
I have the following
cosmosdb_nosql
data setup with a database and 2 containers,conferences
andtalks
:
- **database** - conferences - ```json [ { "endDate": "2022-06-01", "id": "072d1638-a763-49f7-850f-763eed777837", "location": "", "mainTag": "", "name": "CONFERENCE", "startDate": "2022-06-01", "url": "https://example.com/", "year": 2022, "talks": [ { "abstract": "EXAMPLE", "mainTag": "", "tags": [], "talkId": "0c8c7101-26ee-42e9-9596-32ec1d229c0b", "talkLength": 50, "talkTime": null, "title": "EXAMPLE" } ] } ] - talks - ```json [ { "id": "f45a36c0-4031-4779-9461-eeedf37a7b74", "mainTag": "Software Development", "title": "EXAMPLE" } ] ```data setup
The important thing to notice is that there are 3 models, of which 2 need to be exposed as their own entities in DAB:
Conference
, but not its own entity that needs to be exposed!I read the docs which tell me I need to define a graphql schema, on top of the
dab-config.json
, which I imagine has to look like this:
```graphql type Conference @model { id: ID! name: String! location: String year: Int! startDate: String endDate: String url: String mainTag: String talks: [ConferenceTalk!]! } type ConferenceTalk { talkId: ID! title: String! abstract: String mainTag: String talkTime: String talkLength: Int tags: [String] } type Talk @model { id: ID! title: String! mainTag: String } ```GraphQL schema
Which leads me to my
dab-config.json
, which looks like this.
```json { "$schema": "https://github.com/Azure/data-api-builder/releases/download/v1.2.10/dab.draft.schema.json", "data-source": { "database-type": "cosmosdb_nosql", "connection-string": "@env('COSMOSDB_CONNECTIONSTRING')", "options": { "database": "database", "container": null, "schema": "schema.gql" } }, "runtime": { "rest": { "enabled": false, "path": "/api", "request-body-strict": true }, "graphql": { "enabled": true, "path": "/graphql", "allow-introspection": true }, "host": { "cors": { "origins": [], "allow-credentials": false }, "authentication": { "provider": "StaticWebApps" }, "mode": "development" } }, "entities": { "Conference": { "source": { "object": "conferences" }, "graphql": { "enabled": true, "type": { "singular": "Conference", "plural": "Conferences" } }, "rest": { "enabled": false }, "permissions": [ { "role": "anonymous", "actions": [ { "action": "read" } ] } ] }, "Talk": { "source": { "object": "talks" }, "graphql": { "enabled": true, "type": { "singular": "Talk", "plural": "Talks" } }, "rest": { "enabled": false }, "permissions": [ { "role": "anonymous", "actions": [ { "action": "read" } ] } ] }, "ConferenceTalk": { "source": { "object": "WE_DO_NOT_EXPOSE_THIS_BUT_NEED_IT_TO_GET_DAB_TO_WORK" }, "graphql": { "enabled": false }, "rest": { "enabled": false }, "permissions": [ { "role": "anonymous", "actions": [ { "action": "read" } ] } ] } } } ```dab-config.json
The problem
I struggled with this for a long while. In order to get both
ConferenceTalk
andTalk
to work, I must defineConferenceTalk
as an entity indab-config.json
, which is what the error also says. However, this doesn't make sense becauseConferenceTalk
is not its own entity and should not need to be exposed.Expected solution
I should not need to define entities like
ConferenceTalk
indab-config.json
for objects that are part of main/parent entities. What if I had objects 10 layers deep? Would I need to define all of them as entities indab-config.json
? This would lead to a hugedab-config.json
with filler data, just likeConferenceTalk
is now.Extra
Please improve the docs about defining graphql yourself for cosmosdb. They're very limited. I have no idea why/if I need to define
@model
, for example.Version
Microsoft.DataApiBuilder 1.2.10+c7ca8db8558a63919c530e454c8f18b45d5b931c
What database are you using?
CosmosDB NoSQL
What hosting model are you using?
Local (including CLI)
Which API approach are you accessing DAB through?
GraphQL
Relevant log output
Code of Conduct