GraphQL is a query language designed to build client applications by providing a flexible syntax and system for describing their data requirements and interactions. Using GraphQL service, you can query specific data to the server and get the response in a predictable way.
Integration Server 10.4 acts as a GraphQL service provider and supports GraphQL version 9.X.
You can use the Service Development perspective in Designer to create GraphQLdescriptors. A GraphQL descriptor is created using a GraphQL schema and you must provide a valid GraphQL schema. Integration Server uses the GraphQL schema to create the GraphQL descriptor.
Supported and Unsupported GraphQL Features:
Supported:
The basic GraphQL concepts: Schema, Operations, Types, Data resolvers, and Type resolvers.
Root operations for the resources: Query and Mutation. Integration Server performs any GET, POST, UPDATE, or DELETE operation using these two operations.
Input and output data types: Scalar type, Object type, Interface type, Union type, Input object type, Enum type.
Unsupported:
Subscription root operation.
Custom scalar data type.
Directives.
GraphQL uses Resolvers that provide the instructions for turning a GraphQL operation into data. Resolvers are organized into a one to one mapping to the fields in a GraphQL schema. GraphQL uses two types of Resolvers operation:
1> Data resolvers
2> Type resolvers
Import the attached package as I have created the GraphQL descriptors by the attached sample "student.graphql" Graphql schema and built the implementation logic in the "resolvers" service. To ease the POC, I have included the Eh-Cache to store/retrieve the data and make sure you configure the Cache Manager and Cache as shown in the attached screenshot:
student.graphql:
type Query {
greeting:String
students:[Student]
studentById(id:ID!):Student
}
type Student {
id:ID!
firstName:String
lastName:String
collegeId:String
}
type Mutation {
createStudent(id:ID,firstName:String,lastName:String,collegeId:ID):String
}
GraphQl Endpoint:
http://localhost:5555/graphql/GraphqlDemo:Student
Type the following mutation/query in the editor, download the
GraphiQL (A GUI for editing and testing GraphQL queries and mutations) from
https://electronjs.org/apps/graphiql or use Postman v7.2 which supports GraphQL.
Mutation1: (To add data)
mutation {
createStudent(id:"id-1",firstName:"Mahesh",lastName:"Sreenivasulu",collegeId:"colid-1")
}
Response1:
{
"data": {
"createStudent": "id-1"
}
}
Query1: (Get by Id)
{
greeting
studentById(id:"id-1") {
id
firstName
lastName
collegeId
}
}
Response1:
{
"data": {
"greeting": "GraphQL Demo",
"studentById": {
"id": "id-1",
"firstName": "Mahesh",
"lastName": "Sreenivasulu",
"collegeId": "colid-1"
}
}
}
Query2: (Get all)
{
greeting
students {
id
firstName
lastName
}
}
Response2:
{
"data": {
"greeting": "GraphQL Demo",
"students": [
{
"id": "id-2",
"firstName": "Rhea",
"lastName": "Mahesh"
},
{
"id": "id-1",
"firstName": "Mahesh",
"lastName": "Sreenivasulu"
}
]
}
}
Let me know if you have any questions/comments.
For more details refer the product docs at
Cheers,
Mahesh K Sreenivasulu
#webMethods#Integration-Server-and-ESB#graphql-descriptors#Integration-Server#wiki#GraphQL