Lesson 4 of 5 Data API Builder

Exposing Views, Stored Procedures and Relationships

This lesson explains how tables, views and stored procedures are exposed and how relationships enable GraphQL navigation.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain why views need declared key fields.
  • Describe how stored procedure entities work.
  • Distinguish between one, many and many-to-many relationships.

Tables and views

A table entity uses its primary key for single-row operations, and all CRUD actions can be granted. A view has no primary key, so its key columns must be declared: with --source.key-fields in the CLI, or in DAB 2.0 with the fields array and primary-key: true. Views are usually read-only entities, which makes them a good way to publish a curated, denormalized shape without exposing base tables. DAB 2.0's fields array also replaces mappings for aliasing columns and adds descriptions that MCP clients show to agents.

dab add ProductSummary --source "Catalog.vProductSummary" --source.type view \
  --source.key-fields "ProductID" --permissions "anonymous:read"
Scenario questions

Exposing a view

Exam skills 2.4.4

Choose how to expose a view through DAB.

Log in to try this activity Interactive activities are free with an account.

Stored procedures

A stored procedure entity uses source.type: stored-procedure and the execute permission action. Parameters are discovered from the procedure, and defaults and descriptions can be configured. DAB returns the first result set only. Procedures are the way to expose operations that are not simple CRUD, such as semantic search, a RAG question or a multi-table order submission, and for MCP they can be registered as named custom tools with mcp.custom-tool: true.

dab add SearchProducts --source "Api.usp_SearchProducts" --source.type stored-procedure \
  --source.params "query:,top:10" --permissions "authenticated:execute" \
  --rest.methods "get,post" --graphql.operation query
Select all that apply

Procedures as entities

Exam skills 2.4.4

Identify the true statements about stored procedure entities.

Log in to try this activity Interactive activities are free with an account.

Relationships

Relationships let GraphQL clients navigate from one entity to another in one query. A relationship is defined on an entity with a name, a cardinality (one or many), a target.entity and, when no foreign key defines the link (for example with views), source.fields and target.fields. Many-to-many relationships use a linking.object (the junction table) with linking.source.fields and linking.target.fields. Relationships appear only in GraphQL; REST endpoints do not navigate them.

dab update Category --relationship products --target.entity Product \
  --cardinality many --relationship.fields "CategoryID:CategoryID"

# GraphQL
query {
  categories { items { Name products { items { Name ListPrice } } } }
}
Match the pairs

Defining relationships

Exam skills 2.4.4

Match each relationship setting with its purpose.

Log in to try this activity Interactive activities are free with an account.
Worked example

Products by category from a view

A front end needs categories with their products in one GraphQL request. Products are exposed through a view, Catalog.vProductPublic, which hides cost columns. DAB fails to add the view, and later the relationship is not recognized. What must the developer configure?

Add the view as an entity with its key field declared (ProductID), then define a relationship on the Category entity with cardinality many, target the view's entity, and map CategoryID to CategoryID with source and target fields, because a view has no foreign key from which DAB can infer the link. A REST call cannot return nested categories and products, and exposing the base table would reveal the cost columns.

Check yourself

How many result sets does DAB return from a stored procedure?

Show answer

Only the first.

Exam Tips

Remember for the exam

  • Views need declared key fields.
  • Stored procedures: execute action; only the first result set is returned.
  • Relationships: cardinality one or many; linking.object for many-to-many.
  • Relationships are navigated in GraphQL, not REST.