Object-to-table mapping schema NReco.GraphQL documentation
To query your DB tables as Graphql objects mapping schema needs to be configured in the SchemaObjects section:
{
"SchemaObjects": [
{
"SingleName": "company",
"ListName": "companies",
"Table": "Companies",
"Description": "Companies table - contains data about the best companies ever",
"Fields": [
{
"Name": "id",
"Column": "ID",
"DataType": "string",
"Description": "Unique identificator - using also to connect with contact"
},
{
"Name": "title",
"DataType": "string"
}
]
}
]
}
| Property | Purpose |
|---|---|
| Table | Database table name (or view) that corresponds to this object. |
| SingleName | Name that refers to a single object in GraphQL query. |
| ListName | Name that refers to a list of objects in GraphQL query. |
| Description | Object description. Used in results on schema queries (optional). |
| Fields | Definitions of this object's fields. |
| RelatedObjects | Definitions of the objects that may be queried as 'childs' of this object (optional). |
Now we can get a single node or multiple nodes (list of nodes) of the same GraphQL type (or schema) using a simple object query. All fields which have been defined in the object's schema may be used in the graphql query.
Fetch a single company object and a list of companies
query {
company {
id
title
}
companies {
id
title
}
}
{
"data": {
"company": {
"id": 1,
"title": "NReco Inc."
},
"companies": [
{
"id": 1,
"title": "NReco Inc."
},
{
"id": 2,
"title": "Google LLC"
}
}
}
All fields from the schema may be used as parameters in the graphql query:
query {
company(id:2) {
id
title
}
}
{
"data": {
"company": {
"id": 2,
"title": "Google LLC"
}
}
}