Closed sajeetharan closed 7 months ago
Having Authors -> authors mapping somewhere is what we need
Generally when we annotate the other object (in this case Author) as a @model, it creates the mapping with graphql model name to cosmos model name.
But in this case as this is not a model, we don't annotate it, and there is no mapping created in the config so engine is generating the cosmos sql query as select c.id, c.title, c.Authors from c
So as a workaround, having the json field name match exactly with the graphql object name would get it working.
{
"id": "1002",
"title": "Second Foundation",
"Authors": [{
"id": "1",
"first_name": "Isaac",
"middle_name": "",
"last_name": "Asimov"
}]
}
authors->Authors
This could be called a limitation for now, I will also explore a solution
In this case though we shouldn't need the @model
directive for the Author
type as that type isn't one that we want to store outside of the Book
type in our container (and we don't want queries or mutations for).
Is the problem really that the type in GraphQL doesn't match the type that we have in the JSON document, as it's authors
not Authors
?
@sajeetharan can you try changing the case of the field on the document as see if that fixes the problem?
Maybe it's worth adding a directive like @storeAs('...')
so that you can specific a "mapping" between the field in GraphQL and the field in the Cosmos document, allowing you to change casing when it's returned to the client.
@sajeetharan I tried this scenario and it worked fine when in schema file Authors was defined as author.
Below schema would work for your scenario
type Book @model {
id: ID
title: String
authors: [Author] // Notice small case 'a' in authors
}
type Author {
id: ID
first_name: String
middle_name: String
last_name: String
}
changing the case of the field worked for this! closing it for now!
I am trying to update the getting started docs for azure cosmos db with embedded data model type and facing this issue.
Sample Document:
and here is the schema.gql
and config.file
when I tried to query the books and its authors, authors is being returned as null.
query{ books { items{ id, title Authors { id, first_name, last_name } } } }
Result: