<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Muhammad Umar Al Fajar</title>
    <description>The latest articles on DEV Community by Muhammad Umar Al Fajar (@mumaralfajar).</description>
    <link>https://dev.to/mumaralfajar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1252740%2Fea8bd21d-92e2-4470-94bd-bc2fbb659969.png</url>
      <title>DEV Community: Muhammad Umar Al Fajar</title>
      <link>https://dev.to/mumaralfajar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mumaralfajar"/>
    <language>en</language>
    <item>
      <title>Workflow Engine Integration in .NET 8</title>
      <dc:creator>Muhammad Umar Al Fajar</dc:creator>
      <pubDate>Mon, 25 Mar 2024 06:24:55 +0000</pubDate>
      <link>https://dev.to/mumaralfajar/workflow-engine-integration-in-net-8-295a</link>
      <guid>https://dev.to/mumaralfajar/workflow-engine-integration-in-net-8-295a</guid>
      <description>&lt;p&gt;In general, a workflow is a series of activities required to complete a task. In a business context, a workflow refers to a systematic work process where tasks completed by one party are passed on to another party for further action according to certain agreed-upon procedures within the company.&lt;/p&gt;

&lt;p&gt;This workflow can be implemented in .NET using various available tools. Some examples of these tools that already support .NET include &lt;strong&gt;Workflow Engine&lt;/strong&gt; and &lt;strong&gt;Elsaworkflows&lt;/strong&gt;. On this occasion, we will implement Workflow using Workflow Engine as an example.&lt;/p&gt;




&lt;h3&gt;
  
  
  Workflow Engine Integration
&lt;/h3&gt;

&lt;p&gt;To begin integrating .NET with Workflow Engine, make sure that all of the following technologies are installed on your computer:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://visualstudio.microsoft.com/downloads/" rel="noopener noreferrer"&gt;Visual Studio 2022 Community Edition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dotnet.microsoft.com/en-us/download/dotnet/8.0" rel="noopener noreferrer"&gt;.NET 8&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.microsoft.com/en-us/sql-server/sql-server-downloads" rel="noopener noreferrer"&gt;MS SQL Server&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The steps involved in integrating .NET with Workflow Engine are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a blank solution&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7oujyf800ut2kpp8gvcp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7oujyf800ut2kpp8gvcp.png" alt="blank solution"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After the project was created, add new project by right click in the solution then Add &amp;gt; New Project. Choose &lt;strong&gt;Class Library&lt;/strong&gt; and name it &lt;strong&gt;WorkflowLib&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5d9a3f5539wsyghs95kv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5d9a3f5539wsyghs95kv.png" alt="workflow lib"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Add another project with the same step but now choose ASP.NET Core Web App (Model-View-Controller), name it DesignerApp.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqdjuddtsif79zc010zg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcqdjuddtsif79zc010zg.png" alt="designer app"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;h3&gt;
  
  
  Database Preparation
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Download the .NET Core persistence provided by Workflow Engine &lt;a href="https://github.com/optimajet/WorkflowEngine.NET/releases/tag/12.1.1" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Extract the zip file in the folder WorkflowEngine.NET-12.1.1 &amp;gt; Providers &amp;gt; OptimaJet.Workflow.DbPersistence.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the folder is extracted, there will be a folder named SQL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Back to the solution, create a new folder called SQL.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the files to the SQL folder by right-clicking on Solution &amp;gt; Add &amp;gt; Existing Item. Then select all the files in the SQL folder from the previously extracted folder.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xvynsdisg6sv6ldxoju.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5xvynsdisg6sv6ldxoju.png" alt="add sql"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Before executing the SQL file, first create a new database in MS SQL Server and name it WorkflowEngineDb.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After that connect to the database.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhuzts1fx4o9n4lshzm9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhuzts1fx4o9n4lshzm9.png" alt="connect to database"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Then fill in the Server Name and Database Name according to what you have created previously. If the database is not found, try changing Trust Server Certificate to True.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgmu99910vblr1ykebehf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgmu99910vblr1ykebehf.png" alt="select the server"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Back to Visual Studio 2022, open the file CreatePersistanceObjects.sql and click the following button.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw9qcxhq4icgyh1mgclo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frw9qcxhq4icgyh1mgclo.png" alt="execute button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;After the file was executed, a display like this will appear:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31n140sl3e9w1tesu2rt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F31n140sl3e9w1tesu2rt.png" alt="execute success"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Package Preparation
&lt;/h5&gt;

&lt;p&gt;Before starting the integration, there are some packages that need to be added, as follows:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;WorkflowEngine.NETCore-Core&lt;/li&gt;
&lt;li&gt;WorkflowEngine.NETCore-ProviderForMSSQL&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To add the packages above, you can use the following method:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Open Tools &amp;gt; NuGet Package Manager &amp;gt; Manage NuGet Packages for Solution.&lt;/li&gt;
&lt;li&gt;Select Browse and enter the keyword according to the package name above.&lt;/li&gt;
&lt;li&gt;Don't forget to check both projects that were created earlier when installing the package.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1kn1ir01y67vvnrdbw6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fa1kn1ir01y67vvnrdbw6.png" alt="package to install"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  WorkflowRuntime Initiation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Open the WorkflowLib project.&lt;/li&gt;
&lt;li&gt;Create a new class named WorkflowInit.cs.&lt;/li&gt;
&lt;li&gt;Add and adjust the following code according to the project you created.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

using System.Xml.Linq;
using OptimaJet.Workflow.Core.Builder;
using OptimaJet.Workflow.Core.Runtime;
using OptimaJet.Workflow.DbPersistence;

namespace WorkflowLib
{
    public static class WorkflowInit
    {
        [Obsolete]
        private static readonly Lazy&amp;lt;WorkflowRuntime&amp;gt; LazyRuntime = new Lazy&amp;lt;WorkflowRuntime&amp;gt;(InitWorkflowRuntime);

        [Obsolete]
        public static WorkflowRuntime Runtime
        {
            get { return LazyRuntime.Value; }
        }

        public static string ConnectionString { get; set; }

        [Obsolete]
        private static WorkflowRuntime InitWorkflowRuntime()
        {
            // TODO Uncomment for .NET Framework if you don't set ConnectionString externally.
            //ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;

            if (string.IsNullOrEmpty(ConnectionString))
            {
                throw new Exception("Please init ConnectionString before calling the Runtime!");
            }
            // TODO If you have a license key, you have to register it here
            //WorkflowRuntime.RegisterLicense("your license key text");

            // TODO If you are using database different from SQL Server you have to use different persistence provider here.
            var dbProvider = new MSSQLProvider(ConnectionString);

            var builder = new WorkflowBuilder&amp;lt;XElement&amp;gt;(
                dbProvider,
                new OptimaJet.Workflow.Core.Parser.XmlWorkflowParser(),
                dbProvider
            ).WithDefaultCache();

            var runtime = new WorkflowRuntime()
                .WithBuilder(builder)
                .WithPersistenceProvider(dbProvider)
                .EnableCodeActions()
                .SwitchAutoUpdateSchemeBeforeGetAvailableCommandsOn()
                .AsSingleServer();

            var plugin = new OptimaJet.Workflow.Plugins.BasicPlugin();
            // Settings for SendEmail actions
            // plugin.Setting_Mailserver = "smtp.yourserver.com";
            // plugin.Setting_MailserverPort = 25;
            // plugin.Setting_MailserverFrom = "from@yourserver.com";
            // plugin.Setting_MailserverLogin = "login@yourserver.com";
            // plugin.Setting_MailserverPassword = "pass";
            // plugin.Setting_MailserverSsl = true;
            runtime.WithPlugin(plugin);

            // events subscription
            runtime.ProcessActivityChanged += (sender, args) =&amp;gt; { };
            runtime.ProcessStatusChanged += (sender, args) =&amp;gt; { };
            // TODO If you have planned to use Code Actions functionality that required references to external assemblies
            // you have to register them here
            //runtime.RegisterAssemblyForCodeActions(Assembly.GetAssembly(typeof(SomeTypeFromMyAssembly)));

            // starts the WorkflowRuntime
            // TODO If you have planned use Timers the best way to start WorkflowRuntime is somewhere outside
            // of this function in Global.asax for example
            runtime.Start();

            return runtime;
        }
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h5&gt;
  
  
  Connect the MVC with Lib
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Open the DesignerApp&lt;/li&gt;
&lt;li&gt;Right click on the project, then Add &amp;gt; Project Reference&lt;/li&gt;
&lt;li&gt;Check the &lt;strong&gt;WorkflowLib&lt;/strong&gt; and click OK.&lt;/li&gt;
&lt;/ul&gt;
&lt;h5&gt;
  
  
  Project Designer Initiation
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open the DesignerApp project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click on the Controllers folder. Select Add &amp;gt; Controller and name it Designer. After the Controller is added, a new class named DesignerController.cs will appear.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open DesignerController.cs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Right-click on the View() method and select Add View.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then select Razor View - Empty. Then name it Index.cshtml.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the View is added, a new folder and file will appear in the Views folder.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Open the Index.cshtml file and add the following code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

@model dynamic
@{
    ViewBag.Title = "Designer";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

&amp;lt;link href="~/css/workflowdesigner.min.css" rel="stylesheet" type="text/css" /&amp;gt;
&amp;lt;script src="~/js/workflowdesigner.min.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src="~/lib/jquery/dist/jquery.min.js" type="text/javascript"&amp;gt;&amp;lt;/script&amp;gt;

&amp;lt;form action="" id="uploadform" method="post" enctype="multipart/form-data" onsubmit="tmp()" style="padding-bottom: 8px;"&amp;gt;
    &amp;lt;input type="file" name="uploadFile" id="uploadFile" style="display:none" onchange="javascript: UploadScheme(this);"&amp;gt;
&amp;lt;/form&amp;gt;

&amp;lt;div id="wfdesigner" style="min-height:600px; max-width: 1200px;"&amp;gt;&amp;lt;/div&amp;gt;

&amp;lt;script&amp;gt;
    var QueryString = function () {
        // This function is anonymous, is executed immediately and
        // the return value is assigned to QueryString!
        var query_string = {};
        var query = window.location.search.substring(1);
        var vars = query.split("&amp;amp;");
        for (var i = 0; i &amp;lt; vars.length; i++) {
            var pair = vars[i].split("=");
            // If first entry with this name
            if (typeof query_string[pair[0]] === "undefined") {
                query_string[pair[0]] = pair[1];
                // If second entry with this name
            } else if (typeof query_string[pair[0]] === "string") {
                var arr = [query_string[pair[0]], pair[1]];
                query_string[pair[0]] = arr;
                // If third or later entry with this name
            } else {
                query_string[pair[0]].push(pair[1]);
            }
        }
        return query_string;
    }();
    //Load settings
    var schemecode = QueryString.code ? QueryString.code : 'SimpleWF';
    var processid = QueryString.processid;
    var graphwidth = 1200;
    var graphminheight = 600;
    var graphheight = graphminheight;
    var wfdesigner = undefined;

    //Recreate designer object
    function wfdesignerRedraw() {
        var data;
        if (wfdesigner != undefined) {
            wfdesigner.destroy();
        }
        wfdesigner = new WorkflowDesigner({
            name: 'simpledesigner',
            apiurl: '/Designer/API',
            renderTo: 'wfdesigner',
            templatefolder: '/templates/',
            graphwidth: graphwidth,
            graphheight: graphheight
        });
        if (data == undefined) {
            var isreadonly = false;
            if (processid != undefined &amp;amp;&amp;amp; processid != '')
                isreadonly = true;
            var p = { schemecode: schemecode, processid: processid, readonly: isreadonly };
            if (wfdesigner.exists(p))
                wfdesigner.load(p);
            else
                wfdesigner.create(schemecode);
        }
        else {
            wfdesigner.data = data;
            wfdesigner.render();
        }
    }
    wfdesignerRedraw();
    //Adjusts the size of the designer window
    $(window).resize(function () {
        if (window.wfResizeTimer) {
            clearTimeout(window.wfResizeTimer);
            window.wfResizeTimer = undefined;
        }
        window.wfResizeTimer = setTimeout(function () {
            var w = $(window).width();
            var h = $(window).height();
            if (w &amp;gt; 300)
                graphwidth = w - 40;
            if (h &amp;gt; 300)
                graphheight = h - 250;
            if (graphheight &amp;lt; graphminheight)
                graphheight = graphminheight;
            wfdesigner.resize(graphwidth, graphheight);
        }, 150);
    });
    $(window).resize();



    $(window).resize();
    //Add Control functions

    function DownloadScheme() {
        wfdesigner.downloadscheme();
    }
    function DownloadSchemeBPMN() {
        wfdesigner.downloadschemeBPMN();
    }
    var selectSchemeType;
    function SelectScheme(type) {
        if (type)
            selectSchemeType = type;
        var file = $('#uploadFile');
        file.trigger('click');
    }
    function UploadScheme(form) {
        if (form.value == "")
            return;
        if (selectSchemeType == "bpmn") {
            wfdesigner.uploadschemeBPMN($('#uploadform')[0], function () {
                wfdesigner.autoarrangement();
                alert('The file is uploaded!');
            });
        }
        else {
            wfdesigner.uploadscheme($('#uploadform')[0], function () {
                alert('The file is uploaded!');
            });
        }
    }
    function OnSave() {
        wfdesigner.schemecode = schemecode;
        var err = wfdesigner.validate();
        if (err != undefined &amp;amp;&amp;amp; err.length &amp;gt; 0) {
            alert(err);
        }
        else {
            wfdesigner.save(function () {
                alert('The scheme is saved!');
            });
        }
    }

    function OnNew() {
        wfdesigner.create();
    }

&amp;lt;/script&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;In addition, add and adjust the following code to the DesignerController.cs class.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

using System.Collections.Specialized;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using OptimaJet.Workflow;
using WorkflowLib;

namespace DesignerApp.Controllers
{
    public class DesignerController : Controller
    {
        public IActionResult Index()
        {
            return View();
        }

        [Obsolete]
        public async Task&amp;lt;IActionResult&amp;gt; Api()
        {
            Stream? filestream = null;
            var isPost = Request.Method.Equals("POST", StringComparison.OrdinalIgnoreCase);
            if (isPost &amp;amp;&amp;amp; Request.Form.Files != null &amp;amp;&amp;amp; Request.Form.Files.Count &amp;gt; 0)
                filestream = Request.Form.Files[0].OpenReadStream();

            var pars = new NameValueCollection();
            foreach (var q in Request.Query)
            {
                pars.Add(q.Key, q.Value.First());
            }


            if (isPost)
            {
                var parsKeys = pars.AllKeys;
                //foreach (var key in Request.Form.AllKeys)
                foreach (string key in Request.Form.Keys)
                {
                    if (!parsKeys.Contains(key))
                    {
                        pars.Add(key, Request.Form[key]);
                    }
                }
            }

            (string res, bool hasError) = await WorkflowInit.Runtime.DesignerAPIAsync(pars, filestream);

            var operation = pars["operation"]?.ToLower();
            if (operation == "downloadscheme" &amp;amp;&amp;amp; !hasError)
                return File(Encoding.UTF8.GetBytes(res), "text/xml");
            else if (operation == "downloadschemebpmn" &amp;amp;&amp;amp; !hasError)
                return File(UTF8Encoding.UTF8.GetBytes(res), "text/xml");

            return Content(res);
        }
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;After that, download the workflowdesigner.min.css and workflowdesigner.min.js files from &lt;a href="https://github.com/optimajet/WorkflowEngine.NET/tree/master/Designer" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;. Then copy and paste the two files into the project in the css and js folders as follows.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjblmbamdz4urmipt9c5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftjblmbamdz4urmipt9c5.png" alt="paste location"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Also add and adjust the site.css file to be as follows to decorate the designer view.&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
    margin-bottom: 60px;
}

a {
    outline: none;
    text-decoration: none;
}

.ui {
    padding: 8px 15px;
}

.ui.primary.button,
.ui.primary.button:focus {
    background: #f2f2f2;
    border: 1px solid #f2f2f2;
    border-radius: 2px;
    font-weight: normal;
    color: #2c2c2c;
}

    .ui.primary.button:hover {
        background: #c9c9c9;
    }

    .ui.primary.button:active {
        background: #b5b5b5;
    }

.ui.secondary.button,
.ui.secondary.button:focus {
    background: #FFFFFF;
    border: 1px solid #f2f2f2;
    border-radius: 2px;
    font-weight: normal;
    color: #4d4d4d;
}

.ui.secondary.button:hover {
    background: #dbdbdb;
    color: #2c2c2c;
}

.ui.secondary.button:active {
    background: #dbdbdb;
    color: #2c2c2c;
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h5&gt;
  
  
  Connect to Database
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open appsettings.json in the root project DesignerApp.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add ConnectionStrings according to the database on each device, for example as follows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "ConnectionStrings": {
    "DefaultConnection": "data source=mumarual\\SQLEXPRESS;initial catalog=WorkflowEngineDb;trusted_connection=true;TrustServerCertificate=true"
  },
  "AllowedHosts": "*"
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;Then add the following code to Program.cs to set the default ConnectionString for the WorkflowInit.cs class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;WorkflowInit.ConnectionString = app.Configuration.GetConnectionString("DefaultConnection");&lt;/code&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  Run The Project
&lt;/h5&gt;

&lt;p&gt;Before running the project, to make it easier to access the designer, we will add a new button to the application's navbar.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open the Views &amp;gt; Shared folder. Select _Layout.cshtml.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add the Designer controller to the list in the navbar as follows.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

&amp;lt;li class="nav-item"&amp;gt;
    &amp;lt;a class="nav-link text-dark" asp-area="" asp-controller="Designer" asp-action="Index"&amp;gt;Workflow Designer&amp;lt;/a&amp;gt;
&amp;lt;/li&amp;gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Then try running the project by pressing the play button in Visual Studio 2022.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Don't forget to set the startup project as follows to only run DesignerApp.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftw7pq0bxgt3v16yfj4zq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftw7pq0bxgt3v16yfj4zq.png" alt="configure startup project"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1srowp965ilbicqf1rs0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1srowp965ilbicqf1rs0.png" alt="set the startup"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Select the Workflow Designer menu on the navbar and the Designer is ready to use.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flfitzwd6rafo3pbtxw87.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Flfitzwd6rafo3pbtxw87.png" alt="workflow engine"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mumaralfajar/we-net" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Create ASP.Net Core Application with React and TypeScript</title>
      <dc:creator>Muhammad Umar Al Fajar</dc:creator>
      <pubDate>Tue, 19 Mar 2024 01:04:22 +0000</pubDate>
      <link>https://dev.to/mumaralfajar/create-aspnet-core-application-with-react-and-typescript-5911</link>
      <guid>https://dev.to/mumaralfajar/create-aspnet-core-application-with-react-and-typescript-5911</guid>
      <description>&lt;p&gt;This tutorial will walk you through the steps of developing a web application using ASP.NET Core, React, and Typescript. We will start with the initial setup in Visual Studio and then move on to implementing React and using Typescript. This tutorial is intended for beginners who are new to these technologies.&lt;/p&gt;

&lt;p&gt;Before we start, make sure to have these installed:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;I recommend using Visual Studio Community 2022 because it's free and the latest version (as of this writing).&lt;/li&gt;
&lt;li&gt;You'll also need the .NET SDK 8.0. This provides the tools and libraries needed to build and run .NET applications.&lt;/li&gt;
&lt;li&gt;Additionally, Node.js (which includes NPM and NPX) will be required for working with front-end technologies.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  Create ASP.Net Core and React Projects
&lt;/h2&gt;

&lt;p&gt;We will start by using ASP.NET Core and React to create a web-based application. Here are the steps to create a project using Visual Studio 2022:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Open Visual Studio 2022, then select Create a new project.&lt;/li&gt;
&lt;li&gt;After that, search for and select React and ASP.NET Core.&lt;/li&gt;
&lt;li&gt;Select Next, adjust .NET to version 8.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vix0as0wco0kbg3w5op.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5vix0as0wco0kbg3w5op.png" alt="Create ASP.Net Core Application with React"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After creating the project, you will see two folders in your solution: client and server. The client folder contains the React application, and the server folder contains the ASP.NET Core API.&lt;br&gt;
To run the project, press the Play button in Visual Studio. This will start both the client and server applications.&lt;br&gt;
You should see two browsers open: one for the API and one for the user interface. The API browser will display a list of endpoints that you can use to interact with the application. The user interface browser will display the React application.&lt;/p&gt;

&lt;p&gt;if you find an error like this:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

[vite] http proxy error at /weatherforecast:
AggregateError


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This happens because the process of running the client application is faster than the server so when the client requests data to the server, the server will not respond.&lt;/p&gt;

&lt;p&gt;Once the server application running, refresh the client application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7xzlfskkj1ak6rc4l3gm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7xzlfskkj1ak6rc4l3gm.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Add TypeScript to an existing ASP.NET Core app in Visual Studio
&lt;/h2&gt;

&lt;h4&gt;
  
  
  Install TypeScript
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;In the Solution Explorer, right-click on the solution name or the project name and select Manage NuGet Packages.&lt;/li&gt;
&lt;li&gt;Search for and select Microsoft.Typescript.MSBuild. Make sure the project is checked in the right pane and click Install.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Create a TypeScript configuration file
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Right-click on the project name. Click Add &amp;gt; New Item.&lt;/li&gt;
&lt;li&gt;Select TypeScript JSON Configuration File. Click Add. If you don't see any options, click Show All Templates and search for 
Typescript Json Configuration File.&lt;/li&gt;
&lt;li&gt;Open tsconfig.json and replace the code with the following:
```
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;{&lt;br&gt;
    "compileOnSave": true,&lt;br&gt;
    "compilerOptions": {&lt;br&gt;
        "noImplicitAny": false,&lt;br&gt;
        "noEmitOnError": true,&lt;br&gt;
        "removeComments": false,&lt;br&gt;
        "sourceMap": true,&lt;br&gt;
        "target": "es5",&lt;br&gt;
        "outDir": "wwwroot/js"&lt;br&gt;
    },&lt;br&gt;
    "include": [&lt;br&gt;
        "scripts/*&lt;em&gt;/&lt;/em&gt;"&lt;br&gt;
    ]&lt;br&gt;
}&lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
####Create a TypeScript file

 * Right-click on the project name &amp;gt; Add &amp;gt; New Folder. Name the folder scripts.
 * Right-click on the scripts folder &amp;gt; Add &amp;gt; New Item &amp;gt; select TypeScript file. Name the file app.ts.

####Add code to the TypeScript file

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;function TSButton() {&lt;br&gt;
    let name: string = "Fred";&lt;br&gt;
    document.getElementById("ts-example").innerHTML = greeter(user);&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;class Student {&lt;br&gt;
    fullName: string;&lt;br&gt;
    constructor(public firstName: string, public middleInitial: string, public lastName: string) {&lt;br&gt;
        this.fullName = firstName + " " + middleInitial + " " + lastName;&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;interface Person {&lt;br&gt;
    firstName: string;&lt;br&gt;
    lastName: string;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;function greeter(person: Person) {&lt;br&gt;
    return "Hello, " + person.firstName + " " + person.lastName;&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;let user = new Student("Fred", "M.", "Smith"); &lt;/p&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
 * Customize: Feel free to change the code as you like. Try modifying the greeter function or changing the values used to create the Student object.
 * IntelliSense: Visual Studio provides IntelliSense for TypeScript. If you remove "lastName" in the greeter function, for example, and press Ctrl + space, you will see suggestions based on the "Person" interface.

####Modify Index.cshtml
 * Open Views -&amp;gt; Home -&amp;gt; Index.cshtml. Add the following at the end of the file:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;br&amp;gt;

    Click Me
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
####Modify _Layout.cshtml
 * Open Views -&amp;gt; Shared -&amp;gt; _Layout.cshtml. Add the following before @await RenderSectionAsync("Scripts", required: false)
`&amp;lt;script src="~/js/app.js"&amp;gt;&amp;lt;/script&amp;gt;`

####Build and Run

 * Save all changes.
 * In the toolbar, click Build &amp;gt; Build Solution.
 * Look in the wwwroot/js folder. You should see two files: app.js and app.js.map. This indicates the build was successful.
 * Press F5 to run the program.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>aspdotnet</category>
      <category>react</category>
      <category>typescript</category>
    </item>
    <item>
      <title>Learning GraphQL: A Practical Approach</title>
      <dc:creator>Muhammad Umar Al Fajar</dc:creator>
      <pubDate>Wed, 10 Jan 2024 10:42:43 +0000</pubDate>
      <link>https://dev.to/mumaralfajar/learning-graphql-a-practical-approach-4n3g</link>
      <guid>https://dev.to/mumaralfajar/learning-graphql-a-practical-approach-4n3g</guid>
      <description>&lt;p&gt;In this article, we will embark on a practical journey to learn GraphQL. We will set up a simple Apollo Server that serves static data using GraphQL. This approach allows us to focus on the core concepts of GraphQL without the added complexity of a database. &lt;/p&gt;

&lt;p&gt;We will start by setting up our project and installing the necessary dependencies. Then, we will define our GraphQL schema and resolvers. Finally, we will start our server and test it by running some GraphQL queries. &lt;/p&gt;

&lt;p&gt;This hands-on approach is designed to provide a solid foundation in GraphQL. By the end of this article, you will have a working Apollo Server and a clear understanding of how to define and use GraphQL schemas and resolvers.  Let's dive in and start learning GraphQL!&lt;/p&gt;




&lt;h2&gt;
  
  
  Step 1: Setting up the project
&lt;/h2&gt;

&lt;p&gt;First, we need to set up our project and install the necessary dependencies. We will be using npm (Node Package Manager) to manage our dependencies.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm init -y
npm install express graphql apollo-server
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In your package.json file, you should have the following dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"dependencies": {
  "apollo-server": "^3.13.0",
  "graphql": "^16.8.1",
  "express": "~4.16.1"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you don't have these dependencies, you can install them by running the following command in your terminal:&lt;br&gt;
&lt;code&gt;npm install apollo-server graphql&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 2: Defining the GraphQL schema
&lt;/h2&gt;

&lt;p&gt;Next, we need to define our GraphQL schema. The schema defines the types of data that can be queried through our GraphQL server. In our case, we have a Book type, Author type, and a Query type in our schema/schema.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { gql } = require('apollo-server');

const typeDefs = gql`
  type Book {
    title: String!
    author: Author!
  }

  type Author {
    name: String!
    books: [Book]
  }

  type Query {
    books: [Book]
    authors: [Author]
  }
`;

module.exports = typeDefs;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Book type represents a book with a title and an author. The Author type represents an author with a name and a list of books. The Query type defines the queries that can be made to our server. In this case, we have a &lt;strong&gt;books query&lt;/strong&gt; that returns an array of books and an &lt;strong&gt;authors query&lt;/strong&gt; that returns an array of authors.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Defining the resolvers
&lt;/h2&gt;

&lt;p&gt;After defining our schema, we need to define our resolvers. The resolvers specify how the data for each type is fetched. In our resolvers/resolvers.js file, we have defined a resolver for the books query and the &lt;strong&gt;authors query&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const authors = [
  {
    name: 'J.K. Rowling',
    books: [
      {
        title: 'Harry Potter and the Chamber of Secrets',
      },
      {
        title: 'Harry Potter and the Philosopher\'s Stone',
      },
    ],
  },
  {
    name: 'Michael Crichton',
    books: [
      {
        title: 'Jurassic Park',
      },
      {
        title: 'The Lost World',
      },
    ],
  },
];

const resolvers = {
  Query: {
    books: () =&amp;gt; authors.flatMap(author =&amp;gt; author.books),
    authors: () =&amp;gt; authors,
  },
  Book: {
    author: (book) =&amp;gt; authors.find(author =&amp;gt; author.books.some(b =&amp;gt; b.title === book.title)),
  },
  Author: {
    books: (author) =&amp;gt; author.books,
  },
};

module.exports = resolvers;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The books resolver returns an array of static book data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Starting the server
&lt;/h2&gt;

&lt;p&gt;Finally, we need to start our server. We do this in our app.js file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const { ApolloServer } = require('apollo-server');
const typeDefs = require('./schema/schema');
const resolvers = require('./resolvers/resolvers');

const server = new ApolloServer({ typeDefs, resolvers });

server.listen().then(({ url }) =&amp;gt; {
  console.log(`🚀 Server ready at ${url}`);
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We create an instance of ApolloServer with our schema and resolvers, and then start the server by calling the listen method. The server will be listening on the default port (4000) and will log a message to the console when it's ready.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ACVRsNOO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/flcqhbnwacszoqj7xf24.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ACVRsNOO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/flcqhbnwacszoqj7xf24.png" alt="ready log message" width="800" height="177"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's it! You now have a working Apollo Server that serves static data using GraphQL. You can test your server by opening your browser and navigating to &lt;code&gt;http://localhost:4000&lt;/code&gt;. This will open the Apollo Server playground, where you can run GraphQL queries to test your server.  Here are some example queries you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Query for all books with their authors
query {
  books {
    title
    author {
      name
    }
  }
}

# Query for all authors with their books
query {
  authors {
    name
    books {
      title
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Here is the result:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--n7HJOClr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuojeypdigknpl1fov2l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--n7HJOClr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uuojeypdigknpl1fov2l.png" alt="Query for all books with their authors" width="794" height="838"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Y5cJizvp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4h2jy1rc43d8rwkh9fn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Y5cJizvp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h4h2jy1rc43d8rwkh9fn.png" alt="Query for all authors with their books" width="794" height="771"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>graphql</category>
      <category>express</category>
    </item>
  </channel>
</rss>
