News combit Dev Blog

New GraphQL Data Provider for List & Label

Posted: Tuesday, December 17, 2019 | 0 comment(s)
 
GraphQL was publicly released in 2015 and became quite popular since then. It's used by a number of big web applications like Instagram, Facebook and others.

According to the GraphQL specification, it is "a query language designed to build client applications by providing an intuitive and flexible syntax and system for describing their data requirements and interactions".

Starting with version 25, connecting List & Label with a GraphQL API as data source is as simple as creating a new List & Label GraphQLDataProvider object and passing your API address as URL constructor parameter.

GraphQLDataProvider prov = new GraphQLDataProvider("https://localhost:44375/api/graphql");
First, the data provider will try to extract the types and queries defined in the GraphQL server by looking at the schema and - based on that - it will create tables, rows, columns and relations.

Queries that are created as tables have a "Q_" prefix in their name. The prefix can be changed by giving a new prefix to the optional constructor parameter "queryPrefix" of the GraphQLDataProvider class. These queries are the only elements that can be used on the "root" level to print and design, as calling a query is the only way to get actual data in GraphQL. The type-based tables can only be used as child tables of queries as shown below. Query parameters will automatically be added as report parmeters.

There are two other properties in this data provider:
  • QueriesRootName: GraphQL server packs all the queries as fields of one single type. By default, the name of the queries type is "Query", but if your API is different, you need to inform List & Label about this fact.
  • MutationsRootName: a mutation is a write followed by a fetch. Because writing the database is not needed nor supported from the reporting side, mutations must not be part of the structure in the Designer. GraphQL server packs all of the mutations as fields of one single type. By default, the name of the mutations type is "Mutation", but if your API is different, you need to inform List & Label about it in order to exclude the mutations from the data structure.

If your GraphQL data source is to support images, you can serialize and transfer them using GraphQL via Base64 string encoding. To decode these fields back to Bitmap for ListLabel, you can use ListLabel AutoDefineField event. the following code shows how to do it in a Northwind sample:

LL.AutoDefineField += new AutoDefineElementHandler(LL_AutoDefineField);
 
void LL_AutoDefineField(object sender, AutoDefineElementEventArgs e)
{
    string name = e.Name.ToString();
    string value = e.Value.ToString();
    if (name == "Q_categories.picture")
    {
        ListLabel ll = sender as ListLabel;
        e.Suppress = true;
        if (value.Length > 50 && value.Length % 4 == 0)
        {
            ll.Fields.Add(e.Name, Convert.FromBase64String(value));                   
        }
        else
        {
            ll.Fields.Add(e.Name, string.Empty, LlFieldType.Drawing_hBitmap);
        }               
    }
}
This is what the Designer looks like when connecting to a simple Northwind service. Note that we're using the Query Q_Categories as root table, not the Type "Category".



Of course, you may also add a GraphQL data source to the Report Server. It also supports to pass authentication information to access your API.


Free List & Label trial for 30 days.




Author: Jochen Bartlau
Head of Development List & Label

Jochen Bartlau leads the development at combit as Managing Director. He's a Microsoft .NET enthusiast driving innovation & agile project management. The mobile devices geek who used to be a physicist in his first life loves to spend his spare time with his family.


  

RSS
combit Development BlogRSS
What’s this blog for?
A place to share updates about the ongoing development of our products. General musings on the software industry included.
Archive
March 2021 (1)
February 2021 (2)
January 2021 (1)
December 2020 (2)
November 2020 (1)
October 2020 (2)
September 2020 (1)
August 2020 (2)
July 2020 (1)
June 2020 (1)
May 2020 (2)
April 2020 (2)
March 2020 (2)
February 2020 (1)
January 2020 (1)
December 2019 (1)
November 2019 (2)
October 2019 (2)
September 2019 (2)
August 2019 (2)
July 2019 (2)
June 2019 (2)
May 2019 (1)
April 2019 (0)
April 2019 (1)
March 2019 (1)
February 2019 (1)
January 2019 (1)
December 2018 (1)
November 2018 (2)
October 2018 (4)
September 2018 (4)
August 2018 (2)
July 2018 (2)
June 2018 (2)
May 2018 (1)
April 2018 (1)
March 2018 (1)
February 2018 (2)
January 2018 (1)
December 2017 (1)
November 2017 (2)
October 2017 (3)
September 2017 (3)
August 2017 (2)
July 2017 (2)
June 2017 (1)
May 2017 (2)
April 2017 (1)
March 2017 (1)
February 2017 (1)
January 2017 (2)
December 2016 (1)
November 2016 (1)
October 2016 (4)
September 2016 (5)
August 2016 (2)
July 2016 (2)
June 2016 (3)
May 2016 (2)
April 2016 (3)
March 2016 (3)
February 2016 (1)
January 2016 (2)
December 2015 (2)
November 2015 (1)
October 2015 (4)
September 2015 (5)
August 2015 (2)
July 2015 (2)
June 2015 (2)
May 2015 (1)
April 2015 (2)
March 2015 (1)
February 2015 (1)
January 2015 (1)
December 2014 (2)
November 2014 (1)
October 2014 (1)
September 2014 (2)
August 2014 (1)
July 2014 (2)
June 2014 (1)
May 2014 (2)
April 2014 (1)
March 2014 (2)
+1 800 256 3608 (toll-free North America only)