Invoke Graphql query from Adobe IO

Shashi_Mulugu

MVP

06-10-2020

Hello Team,

 

Can anyone help us on how to invoke a Graphql query from Adobe IO runtime environment.

 

Basically we are trying to build an api layer in Adobe io which acts as middle layer between magento and other consuming applications such as AEM.

 

Any reference invocation or Pseudo code will help.

 

@mhaack @Mihai_Corlan 

View Entire Topic

Nikhil-Kumar

MVP

07-10-2020

@mhaack -

We have extended the createCustomer in our resolvers and we are trying to call the magento and get the data as part of createCustomer call and return in as a response.
  
Our extended createCustomer entry point in cartResolver.js :

 createCustomer: (paramscontext=> {
            return new CreateCustomer({
                emailId: params.input.email
            });
 
From here we are calling a class with get customer method returning the response.
 
return new Promise(async function(resolve,reject){
let ou;
            try {
                output = await client.mutate({
                mutation: gql`mutation($email: String, $firstname: String, $lastname: String, $password: String) {
                    createCustomer(input: { email: $email, firstname: $firstname, lastname: $lastname, password: $password }) {
                        customer {
                            email
                            firstname
                            lastname
                                    }
                    }
                }
                
                    
                    `,
               variables
             });

             if(output && output.data && output.data.createCustomer && output.data.createCustomer.customer){
                 ou = output.data.createCustomer.customer;
             }
            
             
           }
           catch(err){
               console.log('Error',err);
           }
 
resolve(ou);
 
 
 
So we are getting the response from Magento Client in our Node JS code. It's just that, when we are returning it from Adobe IO endpoint it becomes null during the call. If any static response it gets resolved properly.

For ex: If I resolved the below object then I get the output:
let object =
{
            email:"ndata45111f2581@gm.com",
            firstname:'test',
            lastname:"Kumar"
  }
 
and when I add resolve(object) it gives me the proper response for create customer with static data:
{
    "data": {
        "createCustomer": {
            "customer": {
                "email""ndata45111f2581@gm.com",
                "firstname""test",
                "lastname""Kumar"
            }
        }
    }
}
 
 
But when I pass the returned response from Magento directly it resolves null. Although it logs the data.