How to use GraphQL API with Purview
How to use GraphQL API with Purview
?
Purview is a cloud-based data governance service that helps you manage and discover your data assets across your organization. Purview also provides a GraphQL API that allows you to query and manipulate your data assets programmatically. In this article, we will explore some of the features and benefits of using GraphQL API with Purview.
?
What is GraphQL?
GraphQL is a query language and a runtime system for APIs that enables you to specify the exact data you need from a server. GraphQL allows you to fetch complete and structured data in a single request, reducing the number of API calls and the amount of data transferred. GraphQL also supports introspection, which means you can query the schema of the API and discover the available types, fields, and arguments.
?
How to use GraphQL API with Purview?
To use GraphQL API with Purview, you need to have an existing Purview account and a service principal that can access the Purview data plane APIs. You also need to obtain a bearer token that will be used for authentication. For more details on how to set up these prerequisites, see the tutorial on API authentication for Microsoft Purview Data Planes.
?
Once you have the token, you can send a POST request to the following endpoint:
POST https://{{endpoint}}/datamap/api/graphql
The {{endpoint}} value depends on whether you are using the new Purview portal or the classic Purview governance portal. For the new portal, the value is api.purview-service.microsoft.com. For the classic portal, the value is {your_purview_account_name}.purview.azure.com.
?
The body of the request should contain a JSON object with a query field that specifies the GraphQL query you want to execute. For example, the following query returns the guid, typeName, and qualifiedName of all the entities of type azure_storage_account:
{
? "query": "query {
? ? entities (where: {type: {typeName: \"azure_storage_account\"}}) {
? ? guid
? ? typeName
? ? qualifiedName
? ? }
? }"
}?
The response will also be a JSON object with a data field that contains the result of the query. For example, the response for the above query might look like this:
领英推荐
{
? "data": {
? ? "entities": [
? ? ? {
? ? ? ? "guid": "9fb74c11-ac48-4650-95bc-760665c5bd92",
? ? ? ? "typeName": "azure_storage_account",
? ? ? ? "qualifiedName": "https://exampleaccount.core.windows.net"
? ? ? },
? ? ? {
? ? ? ? "guid": "a3b74c11-ac48-4650-95bc-760665c5bd93",
? ? ? ? "typeName": "azure_storage_account",
? ? ? ? "qualifiedName": "https://anotheraccount.core.windows.net"
? ? ? }
? ? ]
? }
}
You can use any HTTP client or tool to send GraphQL requests to Purview, such as Postman, curl, or Python requests. You can also use the GraphQL passthrough support feature in Azure API Management to import your existing GraphQL services as APIs in Azure API Management and leverage its security, observability, and performance benefits.
?
What can you do with GraphQL API with Purview?
The GraphQL API with Purview allows you to perform various operations on your data assets, such as:
?
For more examples and details on how to use the GraphQL API with Purview, see the tutorial on using the GraphQL API with Microsoft Purview.
?
Conclusion
GraphQL API with Purview is a powerful and flexible way to interact with your data assets programmatically. It enables you to fetch complete and structured data in a single request, optimize backend database fetching and data transmission, and use declarative data fetching for selective fields. It also supports introspection, which makes the API self-descriptive and easy to explore. By using GraphQL API with Purview, you can enhance your data governance and discovery capabilities and build your own custom solutions on top of Purview.
?
Links
API authentication for Microsoft Purview Data Planes
Public preview: GraphQL passthrough support in Azure API Management
Use the GraphQL API with Microsoft Purview (Preview) https://learn.microsoft.com/en-us/purview/tutorial-graphql-api.