mirror of
https://github.com/datahub-project/datahub.git
synced 2025-12-02 13:44:39 +00:00
1 line
29 KiB
JavaScript
1 line
29 KiB
JavaScript
"use strict";(self.webpackChunkdocs_website=self.webpackChunkdocs_website||[]).push([[51235],{15680:(e,a,t)=>{t.d(a,{xA:()=>u,yg:()=>m});var n=t(96540);function r(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}function l(e,a){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);a&&(n=n.filter((function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable}))),t.push.apply(t,n)}return t}function i(e){for(var a=1;a<arguments.length;a++){var t=null!=arguments[a]?arguments[a]:{};a%2?l(Object(t),!0).forEach((function(a){r(e,a,t[a])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):l(Object(t)).forEach((function(a){Object.defineProperty(e,a,Object.getOwnPropertyDescriptor(t,a))}))}return e}function s(e,a){if(null==e)return{};var t,n,r=function(e,a){if(null==e)return{};var t,n,r={},l=Object.keys(e);for(n=0;n<l.length;n++)t=l[n],a.indexOf(t)>=0||(r[t]=e[t]);return r}(e,a);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)t=l[n],a.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}var o=n.createContext({}),p=function(e){var a=n.useContext(o),t=a;return e&&(t="function"==typeof e?e(a):i(i({},a),e)),t},u=function(e){var a=p(e.components);return n.createElement(o.Provider,{value:a},e.children)},c="mdxType",g={inlineCode:"code",wrapper:function(e){var a=e.children;return n.createElement(n.Fragment,{},a)}},d=n.forwardRef((function(e,a){var t=e.components,r=e.mdxType,l=e.originalType,o=e.parentName,u=s(e,["components","mdxType","originalType","parentName"]),c=p(t),d=r,m=c["".concat(o,".").concat(d)]||c[d]||g[d]||l;return t?n.createElement(m,i(i({ref:a},u),{},{components:t})):n.createElement(m,i({ref:a},u))}));function m(e,a){var t=arguments,r=a&&a.mdxType;if("string"==typeof e||r){var l=t.length,i=new Array(l);i[0]=d;var s={};for(var o in a)hasOwnProperty.call(a,o)&&(s[o]=a[o]);s.originalType=e,s[c]="string"==typeof e?e:r,i[1]=s;for(var p=2;p<l;p++)i[p]=t[p];return n.createElement.apply(null,i)}return n.createElement.apply(null,t)}d.displayName="MDXCreateElement"},34561:(e,a,t)=>{t.r(a),t.d(a,{assets:()=>u,contentTitle:()=>o,default:()=>m,frontMatter:()=>s,metadata:()=>p,toc:()=>c});t(96540);var n=t(15680);function r(e,a,t){return a in e?Object.defineProperty(e,a,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[a]=t,e}function l(e,a){return a=null!=a?a:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):function(e,a){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);a&&(n=n.filter((function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable}))),t.push.apply(t,n)}return t}(Object(a)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})),e}function i(e,a){if(null==e)return{};var t,n,r=function(e,a){if(null==e)return{};var t,n,r={},l=Object.keys(e);for(n=0;n<l.length;n++)t=l[n],a.indexOf(t)>=0||(r[t]=e[t]);return r}(e,a);if(Object.getOwnPropertySymbols){var l=Object.getOwnPropertySymbols(e);for(n=0;n<l.length;n++)t=l[n],a.indexOf(t)>=0||Object.prototype.propertyIsEnumerable.call(e,t)&&(r[t]=e[t])}return r}const s={title:"DataHub GraphQL CLI",sidebar_label:"GraphQL CLI",slug:"/cli-commands/graphql",custom_edit_url:"https://github.com/datahub-project/datahub/blob/master/docs/cli-commands/graphql.md"},o="DataHub GraphQL CLI",p={unversionedId:"docs/cli-commands/graphql",id:"docs/cli-commands/graphql",title:"DataHub GraphQL CLI",description:"The datahub graphql command provides a powerful interface to interact with DataHub's GraphQL API directly from the command line. This enables you to query metadata, perform mutations, and explore the GraphQL schema without writing custom applications.",source:"@site/genDocs/docs/cli-commands/graphql.md",sourceDirName:"docs/cli-commands",slug:"/cli-commands/graphql",permalink:"/docs/cli-commands/graphql",draft:!1,editUrl:"https://github.com/datahub-project/datahub/blob/master/docs/cli-commands/graphql.md",tags:[],version:"current",frontMatter:{title:"DataHub GraphQL CLI",sidebar_label:"GraphQL CLI",slug:"/cli-commands/graphql",custom_edit_url:"https://github.com/datahub-project/datahub/blob/master/docs/cli-commands/graphql.md"}},u={},c=[{value:"Quick Start",id:"quick-start",level:2},{value:"Core Features",id:"core-features",level:2},{value:"1. Schema Discovery",id:"1-schema-discovery",level:3},{value:"2. Smart Description",id:"2-smart-description",level:3},{value:"3. Recursive Type Exploration",id:"3-recursive-type-exploration",level:3},{value:"4. Operation Execution",id:"4-operation-execution",level:3},{value:"5. Raw GraphQL Execution",id:"5-raw-graphql-execution",level:3},{value:"6. File Support",id:"6-file-support",level:3},{value:"7. LLM-Friendly JSON Output",id:"7-llm-friendly-json-output",level:3},{value:"8. Custom Schema Path",id:"8-custom-schema-path",level:3},{value:"Command Reference",id:"command-reference",level:2},{value:"Global Options",id:"global-options",level:3},{value:"Usage Patterns",id:"usage-patterns",level:3},{value:"Advanced Examples",id:"advanced-examples",level:2},{value:"Complex Search with Filters",id:"complex-search-with-filters",level:3},{value:"Adding Tags to Multiple Entities",id:"adding-tags-to-multiple-entities",level:3},{value:"Batch User Queries",id:"batch-user-queries",level:3},{value:"Schema Introspection",id:"schema-introspection",level:2},{value:"Schema Discovery Modes",id:"schema-discovery-modes",level:3},{value:"Schema File Structure",id:"schema-file-structure",level:3},{value:"Error Handling",id:"error-handling",level:2},{value:"Output Formats",id:"output-formats",level:2},{value:"Pretty Printing (Default)",id:"pretty-printing-default",level:3},{value:"Compact Output",id:"compact-output",level:3},{value:"Integration Examples",id:"integration-examples",level:2},{value:"Shell Scripts",id:"shell-scripts",level:3},{value:"CI/CD Pipelines",id:"cicd-pipelines",level:3},{value:"LLM Integration",id:"llm-integration",level:2},{value:"Benefits for AI Assistants",id:"benefits-for-ai-assistants",level:3},{value:"Use Cases",id:"use-cases",level:3},{value:"JSON Schema Benefits",id:"json-schema-benefits",level:3},{value:"Tips and Best Practices",id:"tips-and-best-practices",level:2},{value:"Troubleshooting",id:"troubleshooting",level:2},{value:"Common Issues",id:"common-issues",level:3}],g={toc:c},d="wrapper";function m(e){var{components:a}=e,t=i(e,["components"]);return(0,n.yg)(d,l(function(e){for(var a=1;a<arguments.length;a++){var t=null!=arguments[a]?arguments[a]:{},n=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(t).filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})))),n.forEach((function(a){r(e,a,t[a])}))}return e}({},g,t),{components:a,mdxType:"MDXLayout"}),(0,n.yg)("h1",{id:"datahub-graphql-cli"},"DataHub GraphQL CLI"),(0,n.yg)("p",null,"The ",(0,n.yg)("inlineCode",{parentName:"p"},"datahub graphql")," command provides a powerful interface to interact with DataHub's GraphQL API directly from the command line. This enables you to query metadata, perform mutations, and explore the GraphQL schema without writing custom applications."),(0,n.yg)("h2",{id:"quick-start"},"Quick Start"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'# Get current user info\ndatahub graphql --operation me\n\n# Search for datasets\ndatahub graphql --operation searchAcrossEntities --variables \'{"input": {"query": "users", "types": ["DATASET"]}}\'\n\n# Execute raw GraphQL\ndatahub graphql --query "query { me { username } }"\n')),(0,n.yg)("h2",{id:"core-features"},"Core Features"),(0,n.yg)("h3",{id:"1-schema-discovery"},"1. Schema Discovery"),(0,n.yg)("p",null,"Discover available operations and understand their structure:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# List all available operations\ndatahub graphql --list-operations\n\n# List only queries or mutations\ndatahub graphql --list-queries\ndatahub graphql --list-mutations\n")),(0,n.yg)("h3",{id:"2-smart-description"},"2. Smart Description"),(0,n.yg)("p",null,"The ",(0,n.yg)("inlineCode",{parentName:"p"},"--describe")," command intelligently searches for both operations and types:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# Describe an operation\ndatahub graphql --describe searchAcrossEntities\n\n# Describe a GraphQL type\ndatahub graphql --describe SearchInput\n\n# Describe enum types to see allowed values\ndatahub graphql --describe FilterOperator\n")),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},"When both operation and type exist with same name:")),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"datahub graphql --describe someConflictingName\n# Output:\n# === OPERATION ===\n# Operation: someConflictingName\n# Type: Query\n# ...\n#\n# === TYPE ===\n# Type: someConflictingName\n# Kind: INPUT_OBJECT\n# ...\n")),(0,n.yg)("h3",{id:"3-recursive-type-exploration"},"3. Recursive Type Exploration"),(0,n.yg)("p",null,"Use ",(0,n.yg)("inlineCode",{parentName:"p"},"--recurse")," with ",(0,n.yg)("inlineCode",{parentName:"p"},"--describe")," to explore all nested types:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# Explore operation with all its input types\ndatahub graphql --describe searchAcrossEntities --recurse\n\n# Explore type with all nested dependencies\ndatahub graphql --describe SearchInput --recurse\n")),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},"Example recursive output:")),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre"},"Operation: searchAcrossEntities\nType: Query\nDescription: Search across all entity types\nArguments:\n - input: SearchInput!\n\nInput Type Details:\n\nSearchInput:\n query: String\n types: [EntityType!]\n filters: SearchFilter\n\nSearchFilter:\n criteria: [FacetFilterInput!]\n\nFacetFilterInput:\n field: String! - Name of field to filter by\n values: [String!]! - Values, one of which the intended field should match\n condition: FilterOperator - Condition for the values\n\nFilterOperator:\n EQUAL - Represents the relation: field = value\n GREATER_THAN - Represents the relation: field > value\n LESS_THAN - Represents the relation: field < value\n")),(0,n.yg)("h3",{id:"4-operation-execution"},"4. Operation Execution"),(0,n.yg)("p",null,"Execute operations by name without writing full GraphQL:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'# Execute operation by name\ndatahub graphql --operation me\n\n# Execute with variables\ndatahub graphql --operation searchAcrossEntities --variables \'{"input": {"query": "datasets", "types": ["DATASET"]}}\'\n\n# Execute with variables from file\ndatahub graphql --operation createGroup --variables ./group-data.json\n')),(0,n.yg)("h3",{id:"5-raw-graphql-execution"},"5. Raw GraphQL Execution"),(0,n.yg)("p",null,"Execute any custom GraphQL query or mutation:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'# Simple query\ndatahub graphql --query "query { me { username } }"\n\n# Query with variables\ndatahub graphql --query "query GetUser($urn: String!) { corpUser(urn: $urn) { info { email } } }" --variables \'{"urn": "urn:li:corpuser:john"}\'\n\n# Query from file\ndatahub graphql --query ./complex-query.graphql --variables ./variables.json\n\n# Mutation\ndatahub graphql --query "mutation { addTag(input: {resourceUrn: \\"urn:li:dataset:...\\", tagUrn: \\"urn:li:tag:Important\\"}) }"\n')),(0,n.yg)("h3",{id:"6-file-support"},"6. File Support"),(0,n.yg)("p",null,"Both queries and variables can be loaded from files:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# Load query from file\ndatahub graphql --query ./queries/search-datasets.graphql\n\n# Load variables from file\ndatahub graphql --operation searchAcrossEntities --variables ./variables/search-params.json\n\n# Both from files\ndatahub graphql --query ./query.graphql --variables ./vars.json\n")),(0,n.yg)("h3",{id:"7-llm-friendly-json-output"},"7. LLM-Friendly JSON Output"),(0,n.yg)("p",null,"Use ",(0,n.yg)("inlineCode",{parentName:"p"},"--format json")," to get structured JSON output perfect for LLM consumption:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# Get operations as JSON for LLM processing\ndatahub graphql --list-operations --format json\n\n# Describe operation with complete type information\ndatahub graphql --describe searchAcrossEntities --recurse --format json\n\n# Get type details in structured format\ndatahub graphql --describe SearchInput --format json\n")),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},"Example JSON output for ",(0,n.yg)("inlineCode",{parentName:"strong"},"--list-operations --format json"),":")),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-json"},'{\n "schema": {\n "queries": [\n {\n "name": "me",\n "type": "Query",\n "description": "Get current user information",\n "arguments": []\n },\n {\n "name": "searchAcrossEntities",\n "type": "Query",\n "description": "Search across all entity types",\n "arguments": [\n {\n "name": "input",\n "type": {\n "kind": "NON_NULL",\n "ofType": {\n "name": "SearchInput",\n "kind": "INPUT_OBJECT"\n }\n },\n "required": true,\n "description": "Search input parameters"\n }\n ]\n }\n ],\n "mutations": [...]\n }\n}\n')),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},"Example JSON output for ",(0,n.yg)("inlineCode",{parentName:"strong"},"--describe searchAcrossEntities --recurse --format json"),":")),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-json"},'{\n "operation": {\n "name": "searchAcrossEntities",\n "type": "Query",\n "description": "Search across all entity types",\n "arguments": [...]\n },\n "relatedTypes": {\n "SearchInput": {\n "name": "SearchInput",\n "kind": "INPUT_OBJECT",\n "fields": [\n {\n "name": "query",\n "type": {"name": "String", "kind": "SCALAR"},\n "description": "Search query string"\n },\n {\n "name": "filters",\n "type": {"name": "SearchFilter", "kind": "INPUT_OBJECT"},\n "description": "Optional filters"\n }\n ]\n },\n "SearchFilter": {...},\n "FilterOperator": {\n "name": "FilterOperator",\n "kind": "ENUM",\n "values": [\n {\n "name": "EQUAL",\n "description": "Represents the relation: field = value",\n "deprecated": false\n }\n ]\n }\n },\n "meta": {\n "query": "searchAcrossEntities",\n "recursive": true\n }\n}\n')),(0,n.yg)("h3",{id:"8-custom-schema-path"},"8. Custom Schema Path"),(0,n.yg)("p",null,"When introspection is disabled or for local development:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# Use local GraphQL schema files\ndatahub graphql --list-operations --schema-path ./local-schemas/\n\n# Describe with custom schema\ndatahub graphql --describe searchAcrossEntities --schema-path ./graphql-schemas/\n\n# Get JSON format with custom schema\ndatahub graphql --list-operations --schema-path ./schemas/ --format json\n")),(0,n.yg)("h2",{id:"command-reference"},"Command Reference"),(0,n.yg)("h3",{id:"global-options"},"Global Options"),(0,n.yg)("table",null,(0,n.yg)("thead",{parentName:"table"},(0,n.yg)("tr",{parentName:"thead"},(0,n.yg)("th",{parentName:"tr",align:null},"Option"),(0,n.yg)("th",{parentName:"tr",align:null},"Type"),(0,n.yg)("th",{parentName:"tr",align:null},"Description"))),(0,n.yg)("tbody",{parentName:"table"},(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--query")),(0,n.yg)("td",{parentName:"tr",align:null},"string"),(0,n.yg)("td",{parentName:"tr",align:null},"GraphQL query/mutation string or path to .graphql file")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--variables")),(0,n.yg)("td",{parentName:"tr",align:null},"string"),(0,n.yg)("td",{parentName:"tr",align:null},"Variables as JSON string or path to .json file")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--operation")),(0,n.yg)("td",{parentName:"tr",align:null},"string"),(0,n.yg)("td",{parentName:"tr",align:null},"Execute named operation from DataHub's schema")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--describe")),(0,n.yg)("td",{parentName:"tr",align:null},"string"),(0,n.yg)("td",{parentName:"tr",align:null},"Describe operation or type (searches both)")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--recurse")),(0,n.yg)("td",{parentName:"tr",align:null},"flag"),(0,n.yg)("td",{parentName:"tr",align:null},"Recursively explore nested types with --describe")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--list-operations")),(0,n.yg)("td",{parentName:"tr",align:null},"flag"),(0,n.yg)("td",{parentName:"tr",align:null},"List all available operations")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--list-queries")),(0,n.yg)("td",{parentName:"tr",align:null},"flag"),(0,n.yg)("td",{parentName:"tr",align:null},"List available query operations")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--list-mutations")),(0,n.yg)("td",{parentName:"tr",align:null},"flag"),(0,n.yg)("td",{parentName:"tr",align:null},"List available mutation operations")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--schema-path")),(0,n.yg)("td",{parentName:"tr",align:null},"string"),(0,n.yg)("td",{parentName:"tr",align:null},"Path to GraphQL schema files directory")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--no-pretty")),(0,n.yg)("td",{parentName:"tr",align:null},"flag"),(0,n.yg)("td",{parentName:"tr",align:null},"Disable pretty-printing of JSON output (default: pretty-print)")),(0,n.yg)("tr",{parentName:"tbody"},(0,n.yg)("td",{parentName:"tr",align:null},(0,n.yg)("inlineCode",{parentName:"td"},"--format")),(0,n.yg)("td",{parentName:"tr",align:null},"choice"),(0,n.yg)("td",{parentName:"tr",align:null},"Output format: ",(0,n.yg)("inlineCode",{parentName:"td"},"human")," (default) or ",(0,n.yg)("inlineCode",{parentName:"td"},"json")," for LLM consumption")))),(0,n.yg)("h3",{id:"usage-patterns"},"Usage Patterns"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# Discovery\ndatahub graphql --list-operations\ndatahub graphql --describe <name> [--recurse]\n\n# Execution\ndatahub graphql --operation <name> [--variables <json>]\ndatahub graphql --query <graphql> [--variables <json>]\n")),(0,n.yg)("h2",{id:"advanced-examples"},"Advanced Examples"),(0,n.yg)("h3",{id:"complex-search-with-filters"},"Complex Search with Filters"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'datahub graphql --operation searchAcrossEntities --variables \'{\n "input": {\n "query": "customer",\n "types": ["DATASET", "DASHBOARD"],\n "filters": [{\n "field": "platform",\n "values": ["mysql", "postgres"]\n }],\n "start": 0,\n "count": 20\n }\n}\'\n')),(0,n.yg)("h3",{id:"adding-tags-to-multiple-entities"},"Adding Tags to Multiple Entities"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'# Add Important tag to a dataset\ndatahub graphql --query \'mutation AddTag($input: TagAssociationInput!) {\n addTag(input: $input)\n}\' --variables \'{\n "input": {\n "resourceUrn": "urn:li:dataset:(urn:li:dataPlatform:mysql,db.users,PROD)",\n "tagUrn": "urn:li:tag:Important"\n }\n}\'\n')),(0,n.yg)("h3",{id:"batch-user-queries"},"Batch User Queries"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'# Get multiple users using raw GraphQL\ndatahub graphql --query \'query GetUsers($urns: [String!]!) {\n users: batchGet(urns: $urns) {\n ... on CorpUser {\n urn\n username\n properties {\n email\n displayName\n }\n }\n }\n}\' --variables \'{"urns": ["urn:li:corpuser:alice", "urn:li:corpuser:bob"]}\'\n')),(0,n.yg)("h2",{id:"schema-introspection"},"Schema Introspection"),(0,n.yg)("p",null,"DataHub's GraphQL CLI provides two modes for schema discovery:"),(0,n.yg)("h3",{id:"schema-discovery-modes"},"Schema Discovery Modes"),(0,n.yg)("ol",null,(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Live Introspection")," (default): Queries the live GraphQL endpoint when no ",(0,n.yg)("inlineCode",{parentName:"li"},"--schema-path")," is provided"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Local Schema Files"),": Uses ",(0,n.yg)("inlineCode",{parentName:"li"},".graphql")," files from the specified directory when ",(0,n.yg)("inlineCode",{parentName:"li"},"--schema-path")," is provided")),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},"Note:")," These modes are mutually exclusive with no fallback between them. If introspection fails, the command will fail with an error. If local schema files are invalid, the command will fail with an error."),(0,n.yg)("h3",{id:"schema-file-structure"},"Schema File Structure"),(0,n.yg)("p",null,"When using ",(0,n.yg)("inlineCode",{parentName:"p"},"--schema-path"),", the directory should contain ",(0,n.yg)("inlineCode",{parentName:"p"},".graphql")," files with:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-graphql"},"# queries.graphql\nextend type Query {\n me: AuthenticatedUser\n searchAcrossEntities(input: SearchInput!): SearchResults\n}\n\n# mutations.graphql\nextend type Mutation {\n addTag(input: TagAssociationInput!): String\n deleteEntity(urn: String!): String\n}\n")),(0,n.yg)("h2",{id:"error-handling"},"Error Handling"),(0,n.yg)("p",null,"The CLI provides clear error messages for common issues:"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},"# Operation not found\ndatahub graphql --describe nonExistentOp\n# Error: 'nonExistentOp' not found as an operation or type. Use --list-operations to see available operations or try a specific type name.\n\n# Missing required arguments\ndatahub graphql --operation searchAcrossEntities\n# Error: Operation 'searchAcrossEntities' requires arguments: input. Provide them using --variables '{\"input\": \"value\", ...}'\n\n# Invalid JSON variables\ndatahub graphql --operation me --variables '{invalid json}'\n# Error: Invalid JSON in variables: Expecting property name enclosed in double quotes\n")),(0,n.yg)("h2",{id:"output-formats"},"Output Formats"),(0,n.yg)("h3",{id:"pretty-printing-default"},"Pretty Printing (Default)"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-json"},'{\n "me": {\n "corpUser": {\n "urn": "urn:li:corpuser:datahub",\n "username": "datahub"\n }\n }\n}\n')),(0,n.yg)("h3",{id:"compact-output"},"Compact Output"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'datahub graphql --operation me --no-pretty\n{"me":{"corpUser":{"urn":"urn:li:corpuser:datahub","username":"datahub"}}}\n')),(0,n.yg)("h2",{id:"integration-examples"},"Integration Examples"),(0,n.yg)("h3",{id:"shell-scripts"},"Shell Scripts"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-bash"},'#!/bin/bash\n# Get all datasets for a platform\nPLATFORM="mysql"\nRESULTS=$(datahub graphql --operation searchAcrossEntities --variables "{\n \\"input\\": {\n \\"query\\": \\"*\\",\n \\"types\\": [\\"DATASET\\"],\n \\"filters\\": [{\\"field\\": \\"platform\\", \\"values\\": [\\"$PLATFORM\\"]}]\n }\n}" --no-pretty)\n\necho "Found $(echo "$RESULTS" | jq \'.searchAcrossEntities.total\') datasets"\n')),(0,n.yg)("h3",{id:"cicd-pipelines"},"CI/CD Pipelines"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-yaml"},'# GitHub Actions example\n- name: Tag Important Datasets\n run: |\n datahub graphql --operation addTag --variables \'{\n "input": {\n "resourceUrn": "${{ env.DATASET_URN }}",\n "tagUrn": "urn:li:tag:Production"\n }\n }\'\n')),(0,n.yg)("h2",{id:"llm-integration"},"LLM Integration"),(0,n.yg)("p",null,"The ",(0,n.yg)("inlineCode",{parentName:"p"},"--format json")," option makes the CLI perfect for LLM integration:"),(0,n.yg)("h3",{id:"benefits-for-ai-assistants"},"Benefits for AI Assistants"),(0,n.yg)("ol",null,(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Schema Understanding"),": LLMs can parse the complete GraphQL schema structure"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Query Generation"),": AI can generate accurate GraphQL queries based on available operations"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Type Validation"),": LLMs understand required vs optional arguments and their types"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Documentation"),": Rich descriptions and examples help AI provide better user assistance")),(0,n.yg)("h3",{id:"use-cases"},"Use Cases"),(0,n.yg)("pre",null,(0,n.yg)("code",{parentName:"pre",className:"language-shell"},'# AI assistant gets complete schema knowledge\ndatahub graphql --list-operations --format json | ai-assistant process-schema\n\n# Generate queries for user requests\ndatahub graphql --describe searchAcrossEntities --recurse --format json | ai-helper generate-query --user-intent "find mysql tables"\n\n# Validate user input against schema\ndatahub graphql --describe createGroup --format json | validate-user-input\n')),(0,n.yg)("h3",{id:"json-schema-benefits"},"JSON Schema Benefits"),(0,n.yg)("ul",null,(0,n.yg)("li",{parentName:"ul"},(0,n.yg)("strong",{parentName:"li"},"Structured data"),": No parsing of human-readable text required"),(0,n.yg)("li",{parentName:"ul"},(0,n.yg)("strong",{parentName:"li"},"Complete type information"),": Includes GraphQL type wrappers (NON_NULL, LIST)"),(0,n.yg)("li",{parentName:"ul"},(0,n.yg)("strong",{parentName:"li"},"Rich metadata"),": Descriptions, deprecation info, argument requirements"),(0,n.yg)("li",{parentName:"ul"},(0,n.yg)("strong",{parentName:"li"},"Consistent format"),": Predictable structure across all operations and types"),(0,n.yg)("li",{parentName:"ul"},(0,n.yg)("strong",{parentName:"li"},"Recursive exploration"),": Complete dependency graphs for complex types")),(0,n.yg)("h2",{id:"tips-and-best-practices"},"Tips and Best Practices"),(0,n.yg)("ol",null,(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Start with Discovery"),": Use ",(0,n.yg)("inlineCode",{parentName:"li"},"--list-operations")," and ",(0,n.yg)("inlineCode",{parentName:"li"},"--describe")," to understand available operations"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Use --recurse"),": When learning about complex operations, ",(0,n.yg)("inlineCode",{parentName:"li"},"--describe --recurse")," shows the complete type structure"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"LLM Integration"),": Use ",(0,n.yg)("inlineCode",{parentName:"li"},"--format json")," when building AI assistants or automation tools"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"File-based Variables"),": For complex variables, use JSON files instead of inline JSON"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Error Handling"),": The CLI provides detailed error messages - read them carefully for debugging"),(0,n.yg)("li",{parentName:"ol"},(0,n.yg)("strong",{parentName:"li"},"Schema Evolution"),": Operations and types can change between DataHub versions - use discovery commands to stay current")),(0,n.yg)("h2",{id:"troubleshooting"},"Troubleshooting"),(0,n.yg)("h3",{id:"common-issues"},"Common Issues"),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},'"Introspection not available"'),": Use ",(0,n.yg)("inlineCode",{parentName:"p"},"--schema-path")," to point to local GraphQL schema files"),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},'"Operation not found"'),": Check spelling and use ",(0,n.yg)("inlineCode",{parentName:"p"},"--list-operations")," to see available operations"),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},'"Type not found"'),": Verify type name casing (GraphQL types are case-sensitive)"),(0,n.yg)("p",null,(0,n.yg)("strong",{parentName:"p"},"Environment issues"),": Ensure DataHub server is running and accessible at the configured endpoint"))}m.isMDXComponent=!0}}]); |