Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Manh Nguyen
Apr 1, 2024
  38
(0 votes)

Introducing Optimizely Graph Client and its advantages

Introduction

Optimizely Graph Client was introduced in mid of March 2024 as a lightweight package that mostly supports generating query to our Optimizely Graph service, but you can use that package for your own GraphQL server.

Optimizely Graph Client plays pivotal roles in facilitating seamless interaction with GraphQL APIs and offers distinct advantages for customers seeking simplicity and efficiency. We'll explore how the Optimizely Graph Client eliminates the need for GraphQL expertise by leveraging LINQ expressions and fluent interfaces, ultimately enhancing the user experience and accelerating development phrase.

You could find the documentation about the package for developers on our Dev guide.

Simplifying Query Builder

For some kind of other tools that require you first to write a GraphQL query into a file and then generate it into C# code, this approach needs to re-generate the client file every time you update your GraphQL query.

With our Optimizely Graph Client, one of the primary advantages is its ability to simplify query builder for developers with limited GraphQL knowledge. While other tools require developers to craft GraphQL queries manually, the Optimizely Graph Client reduces the complexity by allowing developers to express their query requirements using familiar LINQ (Language Integrated Query) and chainable methods. This intuitive approach empowers developers to focus on defining their data requirements in a familiar programming paradigm, without the need to delve into the intricacies of GraphQL syntax.

If you were using FIND (Search & Navigation) client packages you could see a very similar syntax to build a search query to Graph service by leveraging LINQ Expressions and fluent interfaces.

An example to express how to build a simple search query on Alloy site:

public class SearchPageController : PageControllerBase<SearchPage>
    {
        private GraphQueryBuilder _queryBuilder;
        public SearchPageController(GraphQueryBuilder queryBuilder)
        {
            _queryBuilder = queryBuilder;
        }

        public ViewResult Index(SearchPage currentPage, string q, string t, string p = "1")
        {
            var query = _queryBuilder
                .OperationName("Alloy_Sample_Query")
                    .ForType<SitePageData>()
                    .Skip((0)
                    .Limit(10)
                    .Fields(x=>x.Name, x=> x.Url, x=> x.MetaTitle, x=> x.MetaDescription)
                    .Total()
                    .Search(q)
                    .FilterForVisitor()
                    .UsingSynonyms()
                    .Facet(x=>x.ContentType.FacetFilters(t));
            var content = query.GetResultAsync<SitePageData>().Result.Content;
            var model = new SearchContentModel(content);
            return View(model);
        }
    }

The GraphQL query should looks like:

query Alloy_Sample_Query {
  SitePageData(
    skip: 0
    limit: 10
    where: { _fulltext: { match: "plan" }, Status: { eq: "Published" } }
  ) {
    items {
      Name
      Url
      MetaDescription
      MetaTitle
    }
    facets {
      ContentType(filters: ["PageData"]) {
        name
        count
      }
    }
    total
  }
}

Dynamic Query Generation

The Optimizely Graph Client excels in dynamically generating GraphQL queries based on user-defined criteria expressed at runtime. This dynamic query generation capability allows for dynamic customization based on user input or changing requirements. Developers can specify filtering, sorting, or other criteria dynamically, leading to more flexible and adaptable queries.

Personalization

By defining query criteria dynamically, developers can fetch targeted data relevant to their requirements. This personalized approach to data retrieval fosters a deeper understanding of user behavior, enabling data-driven decision-making and more effective optimization strategies.

Enhanced Productivity and Efficiency

By eliminating the need for manual GraphQL query scripting, the Optimizely Graph Client significantly enhances productivity and efficiency for developers. You can build your complex query with just a few lines of code. Instead of managing static queries, developers can focus on building flexible query generation mechanisms that can adapt to changing requirements over time and do not need to keep track of all your queries in some script files anymore. Otherwise, with this approach you can make the unit test or integration test easier to use and your code easy to debug.

Conclusion

In conclusion, the Optimizely Graph Client is a compelling choice for customers who are seeking simplicity, efficiency, and seamless integration in their experimentation and optimization endeavors. Optimizely Graph Client empowers developers to interact with Optimizely GraphQL API intuitively, without requiring specialized knowledge of GraphQL syntax. This approach not only enhances productivity and efficiency but also accelerates experimentation workflows, enabling organizations to unlock the full potential of digital optimization with ease.

Looking Ahead

Currently, the source code is publicly available in our Github repository for any contributor. We’re continuously refining and enhancing the functionalities for the package. Your feedback and your ideas are invaluable in this ongoing process. Please do not hesitate to raise issues or create pull requests to our repository.

Apr 01, 2024

Comments

Please login to comment.
Latest blogs
Optimizely Configured Commerce and Spire CMS - Figuring out Handlers

I recently entered the world of Optimizely Configured Commerce and Spire CMS. Intriguing, interesting and challenging at the same time, especially...

Ritu Madan | Mar 12, 2025

Another console app for calling the Optimizely CMS REST API

Introducing a Spectre.Console.Cli app for exploring an Optimizely SaaS CMS instance and to source code control definitions.

Johan Kronberg | Mar 11, 2025 |

Extending UrlResolver to Generate Lowercase Links in Optimizely CMS 12

When working with Optimizely CMS 12, URL consistency is crucial for SEO and usability. By default, Optimizely does not enforce lowercase URLs, whic...

Santiago Morla | Mar 7, 2025 |

Optimizing Experiences with Optimizely: Custom Audience Criteria for Mobile Visitors

In today’s mobile-first world, delivering personalized experiences to visitors using mobile devices is crucial for maximizing engagement and...

Nenad Nicevski | Mar 5, 2025 |

Unable to view Optimizely Forms submissions when some values are too long

I discovered a form where the form submissions could not be viewed in the Optimizely UI, only downloaded. Learn how to fix the issue.

Tomas Hensrud Gulla | Mar 4, 2025 |

CMS 12 DXP Migrations - Time Zones

When it comes to migrating a project from CMS 11 and .NET Framework on the DXP to CMS 12 and .NET Core one thing you need to be aware of is the...

Scott Reed | Mar 4, 2025