Skip to main content

Wanderlust integration

How Wanderlust Integrates with GraphQL

Entity Definition Using Wanderlust

Wanderlust allows developers to define entities declaratively in a DSL, specifying:

  • Attributes: Fields or properties of the entity (e.g., id, name, createdAt, etc.).
  • Relationships: Connections between entities (e.g., parent-child relationships, references).

These entity definitions act as the source of truth for generating the GraphQL schema dynamically.

Dynamic Schema Generation

Kokos leverages Wanderlust's entity definitions to generate the GraphQL schema through the /schema-creation API.

  • Each Wanderlust-defined entity translates into a GraphQL Type.
  • Attributes of the entity are automatically exposed as GraphQL fields.
  • Relationships defined in Wanderlust are modeled as GraphQL connections or nested queries, enabling users to traverse linked data seamlessly.

The schema generation process ensures that any changes to the Wanderlust entity definitions (e.g., adding new attributes or modifying relationships) are reflected in the GraphQL schema.

GraphQL Query Mapping

Wanderlust entities are directly mapped to GraphQL queries, making data access streamlined. For every Wanderlust entity, Data provides the following capabilities in GraphQL:

  • Fetch All: Retrieve a complete list of all entities of a specific type.
query GetEmployeeList {
getEmployeeList {
code
description
address
city
companyCode
}
}
  • Filtered Fetch: Apply filters based on the entity attributes to retrieve a subset of records.
query GetFilteredEmployeeList {
getFilteredEmployeeList(filter: { code: { EQ: "MILLIN" } }) {
code
description
address
city
companyCode
}
}
  • Fetch Relationships: Query relationships defined in Wanderlust (e.g., fetching parent or child entities).
query GetEmployeeList {
getEmployeeList {
code
description
address
city
companyCode
province {
code
description
}
}
}

Example Workflow

To better understand how Wanderlust and GraphQL interact, consider the following workflow:

Defining an Entity in Wanderlust

An employee entity is defined in Wanderlust with attributes like code, name, address, city and a relationship to the province and state entity.

@Table(dataSourceId = "default_relational_db_playground", query = "SELECT * FROM \"BRENTI0F\" WHERE \"E§TRAG\"='COL'")
@SmeupObj(type = "CNCOL", description = "Employee")
public class CNCOL {

@Id
@Column(table = "BRENTI0F", columnName = "E§CRAG")
@SmeupOav(id = "I/02", type = "CNCOL", description = "Code")
private String code;

@Description
@Column(table = "BRENTI0F", columnName = "E§RAGS")
@SmeupOav(id = "I/01", type = "", description = "Name")
private String description;

@Column(table = "BRENTI0F", columnName = "E§INDI")
@SmeupOav(id = "I/03", type = "", description = "Address")
private String address;

@Column(table = "BRENTI0F", columnName = "E§LOCA")
@SmeupOav(id = "I/04", type = "", description = "City")
private String city;

@Column(table = "BRENTI0F", columnName = "E§PROV")
@SmeupOav(id = "I/05", type = "TAV§P", description = "Province")
private String province;

@Column(table = "BRENTI0F", columnName = "E§CNAZ")
@SmeupOav(id = "I/15", type = "TAV§N", description = "State")
private String state;

@Column(table = "BRENTI0F", columnName = "E§AZIE")
@SmeupOav(id = "I/B2", type = "", description = "Company Code")
private String companyCode;
}

Schema Generation

By calling the /schema-creation API, Data reads the Wanderlust entity and generates the following GraphQL schema:

type CNCOL {
code: String
description: String
address: String
city: String
province: TAVP
state: TAVN
companyCode: String
}

input CNCOLFilterInput {
code: StringFilterOperatorInput
description: StringFilterOperatorInput
address: StringFilterOperatorInput
city: StringFilterOperatorInput
province: StringFilterOperatorInput
state: StringFilterOperatorInput
companyCode: StringFilterOperatorInput
}

input StringFilterOperatorInput {
GT: String
GE: String
LT: String
LE: String
NE: String
EQ: String
LS: [String]
LN: [String]
SC: String
NS: String
BG: String
ED: String
}

type Query {
getProvinceList: [TAVP]
getFilteredProvinceList(filter: TAVPFilterInput): [TAVP]
getEmployeeList: [CNCOL]
getFilteredEmployeeList(filter: CNCOLFilterInput): [CNCOL]
}

GraphQL Query Execution

Users can now execute GraphQL queries, such as fetching all employees and their associated province:

query GetEmployeeList {
getEmployeeList {
code
description
address
city
companyCode
province {
code
description
}
}
}

Benefits of Using Wanderlust in the GraphQL Context

  • Declarative DSL: Entities, attributes, and relationships are defined in a concise, readable DSL, minimizing boilerplate code.
  • Single Source of Truth: Entity definitions drive both the data model and the GraphQL schema, ensuring consistency.
  • Simplified Relationships: Wanderlust's relationship definitions enable GraphQL to support nested and relational queries out-of-the-box.

By tightly integrating Wanderlust with GraphQL, Data ensures a streamlined and efficient process for defining, querying, and managing data, while keeping the underlying system flexible and maintainable.