Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Image result for graphql logo

This article is the second in series, explains the technical details and includes few screenshots to give a preview. If you want to read some background and boring stuff, is covered in the first part.

 

Before going to the details, a few product vision key features I have considered.

  • Leverage what SAP/ABAP has to offer most. ex. ICM, OOPs

  • Modularize the implementation

    • Independent JSON converters

    • GraphQL Service Handler knows nothing about the schema

    • Resolvers can be independent of Schema generation logic



  • BOL Resolvers to generate Dynamic schema and resolve all CRUD operations using GENIL operations

  • Schema can be saved to Database Tables to be re-loaded/configured manually

  • SAP Sessions to improve performance with BOL and retaining Schema across requests

  • Testable Code and ABAP Test Scripts for code coverage


 

Architecture



Architecture Diagram

 

  • GraphQL server is exposed as an ICF service from ABAP, which accepts and provides JSON data

  • ICF handler class takes JSON string and convert to ABAP GraphQL Schema classes and validated

  • Schema is built only for the first time if the Session is enabled

  • The user input Query will be parsed and the Execution Context is created

  • Resolver class will be called for individual resolver identifications

  • Resolver will either go to BOL/GenIL or APIs or can directly talk to DB to fetch data

  • Data will be submitted back to ExecutionContext as JSON classes

  • Finally, JSON classes will be validated and converted to JSON string as ICF service response


 

Accessing the API


Note: currently this is under active development, watch this space for updates and code


MYSAPSSO2 token for authentication

Follows standard SAP authorization like MYSAPSSO2 header/cookie in the Request.

 


API Documentation

GraphQL API provides API documentation by default and can be accessed using Schema Queries. Which will provide information to frontend team to browse through the contract to know what fields/operations are supported by the API

 


Queries — using BP Advanced Search

Query is the way to get some data from API, which is same as HTTP “GET” operations. Query can have Arguments which will help filter the results from the API. Query should end with requesting necessary field by the UI.

 


BP Advanced Search Results

Here we can see the Results as sent back from API, which exactly matches the Requested 4 fields from the server.

 


Mutations — Creating BP with Deep Data

Mutations are a way to change some data on the server. Here we are creating a BP along with the child relations like Address and Marketing Attributes.

 


Mutations — Creating Child data of BP

 


Mutations — Updates and Deletes

 

At a Glance


Packages



  • ZGRAPHQL — Main Package

  • ZGRAPHQL_LANG — contains all the Language/Schema Implementation classes

  • ZGRAPHQL_API — contains base Service classes to expose CRM data as API

  • ZGRAPHQL_CORE — Base Server Classes


Message Class — ZGRAPHQL


Important Classes


ZGQLSCL_SCHEMA




  • responsible for creating the GraphQL Schema (Type System)

  • can create either from Internal Tables or from Database Tables

  • Validates and Creates Schema Object

  • loads all required components into Memory

  • Builds Introspection Resolver and Holds User Resolver


ZGQLCL_API_SERVICE_BASE




  • Base SICF handler class to handle basic functionality of the GraphQL server

  • All Sub-classes are only expected to provide Schema from PREPARE_SCHEMA method


ZGQLCL_TABLES_RESOLVER




  • which builds Schama using given ABAP table names


ZGQLCL_BUIL_GENIL_RESOLVER




  • Class to resolve all Business Partner related BOL operations

  • ZGQLCL_BUIL_CUST_RESOLVER is a specialization which allows restricting

  • BOL entities and Relationships exposed

  • Mapping for the Relationship names


ZGQLSIF_RESOLVER




  • Resolver to provide links to Operation and Data

  • All Implementation classes must provide

  • Schema to be initiated

  • Resolving Method for each Operation


ZGQLSCL_INTROSPEC_RESOLVER




  • responsible for resolving Schema Introspection queries


ZCX_GQL_EXCEPTION




  • Base Exception class available globally to throw Errors

  • The server automatically handles this error and passes to Client as “errors” array in response

  • can handle BOL errors and BAPI errors


ZGQLCL_EXECUTION_CONTEXT




  • the class is responsible for keeping the current Context until the end of the operation execution

  • Validates the current Operation submitted by Client before starting the execution

  • holds Schema, Operation currently being executed, Selections requested by Client


ZGQLCL_EXECUTOR




  • the class is responsible for executing Query, Mutations and handle Errors



  1. EXECUTE_QUERY



  • the method resolves Query operations


2. EXECUTE_MUTATION




  • the method performs Mutation (update) operations


3. EXECUTE_SELECTION_SET




  • method to resolve each field requested by the Client

  • recursively resolves each Custom Type until it reaches Leaf Nodes


ZGQLCL_LOG




  • used for logging the requests to the GraphQL server

  • logs Request Operations, Response Errors

  • Transaction: SLG0, Object — ZGRAPHQL, Sub Object — ZGQL_GEN


ZGQLCL_UTILS




  • utility functions for reading AppSet Entries and Domain Values


 

The benefits I observe from this approach are:

  • Higher Abstraction of the API Implementation

  • Easy Integration using widely popular toolchain on UI running outside SAP

  • Above all, Performance can be tweaked within SAP as we run the logic near Database


 

Even though I started this as an exploring project not knowing if I could finish it on my own or not, spending my evenings and holidays, After seeing the final result, I requested my Manager to spend some time for a small the Demo.

Having no expectations, with the CRM experience my Manager immediately identified the potential of this solution and the advantages our Organization can get in exposing CRM data using GraphQL. With his support, I have managed to present to higher management.

And today we are experimenting and building unified enterprise level services for multiple Web Applications with minimal friction and with High performance. The feedback from the Web developers is that 'Fast development times, Ease of use and more options in choosing client libraries'.

 

Other sources to track this topic.


Part 1

Part 2
2 Comments
Labels in this area