MODULES > REST API and GraphQL > Creating custom schema (SDL/JSON) / custom endpoint
7. Creating custom schema (SDL/JSON) / custom endpoint
The GraphQL REST API exposes in standard a subset of the full HOPEX Metamodel. This subset is organized into several endpoint represented by a schema (SDL). The split is mainly done by solution scope or technical grouping (e.g.: ITPM, BPA, Audit)
It is possible to extend the delivered schema or to create new schema. The result of this customization will end up with a new endpoint to call by HTTP request.
7.1. How it works ?
7.1.1. General principle
To create a schema you need to convert the HOPEX Metamodel into a GraphQL syntax compatible. This mapping is done through a JSON file that maps the HOPEX ID with a naming convention compatible with GraphQL. From this file the system generates a GraphQL syntax. The default JSON mapping schema are installed in the CONFIG folder of the HOPEX installation:
C:\ProgramData\MEGA\Hopex Application Server\<Has instance name>\Modules\hopex.graphql\<GraphQL module version>\CONFIG\V3\Standard
Example:
C:\ProgramData\MEGA\Hopex Application Server\5000\Modules\hopex.graphql\HOPEX GraphQL-7.87.507+6623.zip\CONFIG\V3\Standard
Moreover, in the web part a key in the web.config exposes the list of available schema.
<add key="GraphQLSchemas" value="ITPM, Assessment, Audit, BPA, Data, DataPrivacy, MetaModel, Reporting, Risk, Workflow"/>
<!-- GraphQLSchema-->
In this example there are several schema about: ITPM, Assessment, Audit…
Within this JSON file the metamodel in terms of MetaClass, MetaAttribute, MetaAttributeValue, MetaAssociation.
Here is an extract of a JSON mapping schema for ITPM:
...
"metaclass": [{
"id": "MrUiM9B5iyM0",
"name": "Application",
"description": "An application is a software component that can be deployed and provides users with a set of functionalities.",
...
"properties": [{
"id": "Z20000000D60",
"name": "Name",
"description": "Short Name of the object ...",
"constraints": {
"type": "String",
"mandatory": true,
"maxLength": "1024",
"readOnly": false,
"translatable": true,
"formattedText": false
}}],
"relationships": [
{
"id": "7ChrtiDo4vb0_YChrYpDo4ri0_MrUiM9B5iyM0",
"name": "TimePeriod",
...
"pathToTarget": [
{
"id": "VChrYpDo4fi0",
"name": "TimeDependentObjectTimePeriod",
"maeName": "PeriodOfValidity",
"maeID": "YChrYpDo4ri0",
"metaClassName": "TimePeriod",
"metaClassID": "7ChrtiDo4vb0",
"multiplicity": "*"
}]}]
...
See ITPM file for full JSON:
A screenshot of a computer Description automatically generated
7.1.2. Creating/Updating a schema
To create your own schema you can:
Create a totally new schema
In this case you are free to define what is exposed and you will not be impacted by future updates of the API.
Extend an existing schema.
This limits the customization to be performed but you will benefit from future updates of the default delivered schema..
In both cases the principle is the same. You need to create a custom JSON file that you will put in the custom folder:
C:\...\HOPEX Application Server\<HAS instance name>\.shadowFiles\has.custom\<Module version>\hopex.graphql\<GraphQL module version>\CONFIG\V3\Standard
e.g.: C:\ProgramData\MEGA\HOPEX Application Server\5000\.shadowFiles\has.custom\<Module version>\hopex.graphql\HOPEX GraphQL-7.87.507+6623\CONFIG\V3\Standard
In case of a new JSON the name of the schema must be added in the web.config.
 
7.2. Step 1: Create your metamodel to expose in the REST API
The JSON delivered out of the box have been generated by a java program that reads a diagram of metamodel. To generate a schema JSON you can use the same tool on existing metamodel diagram or with your new metamodel diagram.
7.2.1. Creating Custom Metamodel
1. Connect to HOPEX (Windows Front-End).
2. In the MetaStudio tab create a new Metamodel.
3. Add a new diagram to this metamodel.
4. Add the elements of metamodel you want.
5. Copy and keep for later the absolute identifier of the metamodel object.
A screenshot of a computer Description automatically generated
7.2.2. Completing default metamodel
Should you want to complete the default schema with additional MetaClass, MetaAttribute:
1. Import the MGL file located in "MGL" folder.
2. Duplicate the standard Metamodel and diagram you want to complete.
3. Add the elements of metamodel you want.
4. Copy and keep for later the absolute identifier of the metamodel object.
7.2.3. Important rules
This generator applies the following rules:
Only concrete metamodel is generated
MetaAssociation must be in the diagram to be generated, including the abstract version of the MetaAssociation. 
7.3. Step 2: Configure the generator
From HOPEX store (https://store.mega.com/modules/) download GraphQL Mapping Json Generator modulehttps://community.mega.com/t5/HOPEX-Store/GraphQL-REST-API/td-p/21381
Unzip the GraphQL Mapping Json Generator.haspkg in “java” folder (you may need to create it):
C:\temp\java
You can adjust according to your case:
Open the "00_SchemaToGenerate.json" to add your schema. Past the absolute identifier you have saved from previous step.
Edit the included section to false to avoid generating the other schema.
 
Example of "00_SchemaToGenerate.json":
{
"included": "true",
"schemaName": "ITPM",
"metaModelAbsoluteIdentifier": "TeEKeRMmSPYK",
"login": "Tibere",
"password": "Hopex",
"profile": "ITPM Functional Administrator"
},
Login, password, and profile should reflect the restriction of metamodel you want to apply to the API. If you do not know which profile put 'HOPEX Customizer'. Access right will be read at runtime.
A screenshot of a computer Description automatically generated
 
7.4. Step 3: Run the generator
Before running the generator edit the file 'run.bat' to adjust:
folder location: HOPEX, log, config file
environment path
repository name
debug option (-d)
To run the program, execute the run.bat file. In case of success the message appears in the console.
Processing the request may take between 30 to 45 min... Be patient! depending on the metamodel complexity.
Example of console message in debug:
[2020-09-14 08:35:21] [CONFIG ] debug = true
[2020-09-14 08:35:21] [CONFIG ] verbose = false
[2020-09-14 08:35:21] [CONFIG ] Folder = c:\temp\java\
[2020-09-14 08:35:21] [CONFIG ] Log Folder = c:\temp\java\
[2020-09-14 08:35:21] [CONFIG ] File Name Override = 00_OverrideName_Global.JSON
[2020-09-14 08:35:21] [CONFIG ] File Name Schema = 00_SchemaToGenerate.JSON
[2020-09-14 08:35:21] [CONFIG ] Environment = C:\Users\Public\Documents\HOPEX V4\PRESALESV4
[2020-09-14 08:35:21] [CONFIG ] Repository = SOHO
[2020-09-14 08:35:21] [INFOS ] Read schema name
[2020-09-14 08:35:22] [INFOS ] ########### Starting ###########
[2020-09-14 08:35:22] [INFOS ] ########## Starting : Custom
[2020-09-14 08:35:22] [INFOS ] Open HOPEX
[2020-09-14 08:35:29] [INFOS ] Open Session
[2020-09-14 08:35:29] [INFOS ] sAdministrator: Mega - sPassword: *****
[2020-09-14 08:35:30] [INFOS ] Read overRideName JSON
[2020-09-14 08:35:30] [INFOS ] Creating JSON
[2020-09-14 08:35:30] [INFOS ] Start Metaclass
[2020-09-14 08:35:32] [INFOS ] Size = 1
[2020-09-14 08:35:33] [INFOS ] MetaClass = Application
[2020-09-14 08:36:01] [INFOS ] Starting Reverse Id
[2020-09-14 08:36:01] [INFOS ] Start Interfaces
[2020-09-14 08:36:01] [INFOS ] Wrting filec:\temp\java\SBB.JSON
[2020-09-14 08:36:01] [INFOS ] Write overRideName JSON
[2020-09-14 08:36:01] [INFOS ] HOPEX Closed
[2020-09-14 08:36:01] [INFOS ] ########### All done ###########
 
A screenshot of a computer program Description automatically generated
Advantage: you benefit from dedicated process. Adapted to heavy computation that will need several minutes/hours to respond.
Drawback: takes time to respond.