datahub-graphql-core/README.md
DataHub GraphQL API is a shared lib module containing a GraphQL API on top of the GMS service layer. It exposes a graph-based representation permitting reads and writes against the entities and aspects on the Metadata Graph, including Datasets, CorpUsers, & more.
Contained within this module are
GraphQL object provided by graphql-java. Provides a way to configure all of the important stuff using a simple Builder API.We've chosen to place these components in a library module so that GraphQL servers can be deployed in multiple "modes":
datahub-frontendWhen adding an entity to the GMS graph, the following steps should be followed:
types (Queries) or inputs (Mutations) required for fetching & updating your Entity.These models should generally mirror the GMS models exactly, with notable exceptions:
CorpUser type)In GraphQL, the new Entity should extend the Entity interface. Additionally, you will need to add a new symbol to the standard
EntityType enum.
The convention we follow is to have a top-level Query for each entity that takes a single "urn" parameter. This is for primary key lookups. See all the existing entity Query types here.
On rebuilding the module (./gradlew datahub-graphql-core:build) you'll find newly generated classes corresponding to
the types you've defined inside the GraphQL schema inside the mainGeneratedGraphQL folder. These classes will be used in the next step.
EntityType classes for any new entitiesMappers to transform Pegasus model returned by GMS to an auto-generated GQL POJO. (under /mainGeneratedGraphQL, generated on ./gradlew datahub-graphql-core:build) These mappers
will be used inside the type class defined in step 2.EntityType to the GraphQL schema.We use GmsGraphQLEngine.java to configure the wiring for the GraphQL schema. This means associating "resolvers" to specific fields present in the GraphQL schema file.
Inside of this file, you need to register your new Type object to be used in resolving primary-key entity queries.
To do so, simply follow the examples for other entities.
Implement EntityType test for the new type defined in Step 2. See ContainerTypeTest as an example.
Implement Resolver tests for any new DataFetchers that you needed to add. See SetDomainResolverTest as an example.
[Optional] Sometimes, your new entity will have relationships to other entities, or fields that require specific business logic as opposed to basic mapping from the GMS model. In such cases, we tend to create an entity-specific configuration method in GmsGraphQLEngine.java which allows you to wire custom resolvers (DataFetchers) to the fields in your Entity type. You also may need to do this, depending on the complexity of the new entity. See here for reference.
Note: If you want your new Entity to be "browsable" (folder navigation) via the UI, make sure you implement the
BrowsableEntityTypeinterface.
In order to enable searching an Entity, you'll need to modify the SearchAcrossEntities.java resolver, which enables unified search across all DataHub entities.
Steps:
That should be it!
Now, you can try to issue a search for the new entities you've ingested