June 5, 2024

Introducing Legend GraphQL

Abhishoya Lunavat, Associate; Anand Matta, Vice President

Legend* is an open-source data platform created by Goldman Sachs and contributed to the Fintech Open Source Foundation (FINOS).

In this blog, we will first dive into GraphQL, explore how it streamlines the process of accessing data from multiple sources, paving the way for efficient client-server interactions. We will then discuss building a GraphQL service with Legend through an illuminating example, shedding light on its role in streamlining the SDLC while providing a governed server-side runtime. 

What’s GraphQL and Why Do We Need It?

GraphQL is a declarative API Query language for precise data retrieval. Unlike conventional REST APIs, which often provide fixed data structures, GraphQL empowers clients to dictate the data required in a single query. This core pillar of GraphQL removes the burden on developers to repetitively build APIs for every feature and allows them to focus on core functionality. 

What’s Legend GraphQL?

Legend provides a GraphQL interface for querying modelled data which works out-of-the-box with no additional configuration. It leverages data models and server-side runtime provided by Legend with compatibility to numerous supported relational databases. These connectors can be used through mapping and runtimes which seamlessly implement GraphQL resolvers, allowing federated data fetching across multiple sources. As we will see below, Legend also provides dynamic filters generated by introspecting the model definitions and extending them to allow clients to search capabilities across the graph with tremendous flexibility.

Building a GraphQL Service in Legend

 

Defining the schema

Building a GraphQL service requires defining a schema of types and various fields on those types. We will leverage data modelling features in Legend to build a schema for our service. One of our previous blog posts Building Platforms for Data Engineering discusses data modelling in Legend and introduces a “Firm-Person” logical model. We will use a similar model for our service with entities Firm and Person, and a one-to-many relationship defined between them as shown in the below diagram.

A GraphQL schema must also define a query type at the root level, which represents all the possible entry points to the service. In Legend, we can define this root query type using another class. And for its top-level fields we will define several derived properties.

Resolvers

Next in building our GraphQL service we will need resolvers for our types and their fields. We will leverage Pure language expressions and mappings discussed in detail in a previous blog post to achieve this. For our top-level fields, we define resolvers using Pure language expressions in the derived properties of query class and for all other object/class types, we will define a mapping. This mapping provides resolvers for fields in respective object/class types. In this example our mapping (and runtime) connects our data model to a relational data source. 

Example GraphQL Queries

Let us look at a simple query which fetches all firms’ legal names.

Next, let us try a different query, to fetch employees of “Stark Industries”. We can use the top-level field employeesByFirm which accepts a firm name as an argument.

For our final example, let us try to fetch employees of “Stark Industries” again but this time using the top-level field employees and a dynamic filter on the firm’s legal name. Dynamic filters do not require to be modelled but rather can be defined directly in GraphQL query.

Introspection and Schema Generation in Legend

Apart from querying, Legend also supports introspection of the type-system over its GraphQL API, in adherence to the official specification. This gives users much needed flexibility to use any GraphQL client of their choice. For example, in this blog post, example query snapshots are from an instance of GraphiQL

Legend also supports GraphQL schema generation from Pure models and vice versa which can be leveraged to integrate Legend into an existing GraphQL ecosystem.

Learn More and Get Started

Documentation and Open-Source Code

More presentations, talks and videos can be found on the Legend website 

(*) The open-source contributions mentioned in this article relate to data models. The resulting collaborations involve the exchange of non-proprietary, non-confidential, and non-licensed information only.


See https://www.gs.com/disclaimer/global_email for important risk disclosures, conflicts of interest, and other terms and conditions relating to this blog and your reliance on information contained in it.

GS DAP® is owned and operated by Goldman Sachs. This site is for informational purposes only and does not constitute an offer to provide, or the solicitation of an offer to provide access to or use of GS DAP®. Any subsequent commitment by Goldman Sachs to provide access to and / or use of GS DAP® would be subject to various conditions, including, amongst others, (i) satisfactory determination and legal review of the structure of any potential product or activity, (ii) receipt of all internal and external approvals (including potentially regulatory approvals); (iii) execution of any relevant documentation in a form satisfactory to Goldman Sachs; and (iv) completion of any relevant system / technology / platform build or adaptation required or desired to support the structure of any potential product or activity. All GS DAP® features may not be available in certain jurisdictions. Not all features of GS DAP® will apply to all use cases. Use of terms (e.g., "account") on GS DAP® are for convenience only and does not imply any regulatory or legal status by such term.
Certain solutions and Institutional Services described herein are provided via our Marquee platform. The Marquee platform is for institutional and professional clients only. This site is for informational purposes only and does not constitute an offer to provide the Marquee platform services described, nor an offer to sell, or the solicitation of an offer to buy, any security. Some of the services and products described herein may not be available in certain jurisdictions or to certain types of clients. Please contact your Goldman Sachs sales representative with any questions. Any data or market information presented on the site is solely for illustrative purposes. There is no representation that any transaction can or could have been effected on such terms or at such prices. Please see https://www.goldmansachs.com/disclaimer/sec-div-disclaimers-for-electronic-comms.html for additional information.
Transaction Banking services are offered by Goldman Sachs Bank USA (“GS Bank”). GS Bank is a New York State chartered bank, a member of the Federal Reserve System and a Member FDIC.
Mosaic is a service mark of Goldman Sachs & Co. LLC. This service is made available in the United States by Goldman Sachs & Co. LLC and outside of the United States by Goldman Sachs International, or its local affiliates in accordance with applicable law and regulations. Goldman Sachs International and Goldman Sachs & Co. LLC are the distributors of the Goldman Sachs Funds. Depending upon the jurisdiction in which you are located, transactions in non-Goldman Sachs money market funds are affected by either Goldman Sachs & Co. LLC, a member of FINRA, SIPC and NYSE, or Goldman Sachs International. For additional information contact your Goldman Sachs representative. Goldman Sachs & Co. LLC, Goldman Sachs International, Goldman Sachs Liquidity Solutions, Goldman Sachs Asset Management, L.P., and the Goldman Sachs funds available through Goldman Sachs Liquidity Solutions and other affiliated entities, are under the common control of the Goldman Sachs Group, Inc.
© 2024 Goldman Sachs. All rights reserved.