Looking into graphQL, and just wanted to know, if ...
# suitescript
r
Looking into graphQL, and just wanted to know, if anyone has worked with graphQL? Like reading a graphQL query structure from the request and calling suiteQL to provide the response?
n
Unfortunately I don't have an answer but, that's freaky, I was looking at GraphQL for the first time yesterday. 🙂 I was trying to send a query from the NS debugger but got called away before I could finish the task. Some of the guys in my business, including my son, work with GraphQL but they work in the business as AWS engineers primarily and not NS. Do you have an endpoint you can call to test things out? I've been using the Apollo SpaceX api to figure stuff out. Maybe this will help you too? https://studio.apollographql.com/public/SpaceX-pxxbxen/variant/current/explorer https://github.com/r-spacex/SpaceX-API/tree/master/docs#rspacex-api-docs
r
It's my first time going through graphQL as well. I was using apollographql and https://countries.trevorblades.com/ Just to understand the structure. Based on the graphQL data structure I want to perform queries in Netsuite. I am still trying to wrap around how to do it in terms of suitescript, suiteQL
n
I've been trying to do this, this morning in the NS debugger but keep seeing "bad request" as the response. When I have time i'll look to move it ot a SuiteLet in case the debugger is parsing / formatting it in a way that breaks it. If you make progress I'd be keen to hear from you and happy to share what I find should I make progress.
The curl request Apollo throws out looks like this:
Copy code
curl --request POST \
    --header 'content-type: application/json' \
    --url '<https://spacex-production.up.railway.app/>' \
    --data '{"query":"query ExampleQuery($find: LaunchFind) {\n   launches(find: $find){   \n    launch_date_local\n    id\n    mission_name\n    rocket {      \n      rocket_name\n      rocket_type      \n    }\n  }\n}","variables":{"find":{"id":"5eb87cd9ffd86e000604b32a"}}}'
and my debugger code:
Copy code
require(['N/record', 'N/search', 'N/https'],
        function (record, search, https) {
          function execute () {
            var theUrl = '<https://spacex-production.up.railway.app/>';
            var postData = '{"query":"query ExampleQuery($find: LaunchFind) {\n   launches(find: $find){   \n    launch_date_local\n    id\n    mission_name\n    rocket {      \n      rocket_name\n      rocket_type      \n    }\n  }\n}","variables":{"find":{"id":"5eb87cd9ffd86e000604b32a"}}}'

            var headers = {"content-type":"application/json","Access-Control-Allow-Origin": "*"}
            var myResponse = <http://https.post|https.post>({
              url: theUrl,
              body: postData,
              headers: headers
            });
            var pause = ''; // convenient place to add a breakpoint
          }
          execute();
        });
Just leaving those there in case they are of interest / use to you.
And on Apollo:
r
Thank you, will keep you posted if I make any progress, I am on a similar path, but haven't worked on it much yet.
n
I kept picking at it last night, it's frustrating how tantalisingly close I feel I am but just missing something pertinent.
b
typically i recommend an echo service like postman echo to do the comparison
r
@battkdo you have any knowledge on how to achieve this in Suitescript? like if query is something like this employee(internalid: 1234) { reportingManager Hiredate Jobtitle } suiteQL query can be performed which fetches the data for employee with internal id 1234 and those 3 fields?
b
there is no known graph ql server implementation for suitescript
n
FYI I made the same request using POSTman, same JSON payload and it worked fine. Interestingly there's a GraphQL option for the body which formats that JSON and also works. So I don't believe there's anything wrong directly with my request / headers so I'll try in a suitelet when I get time.
b
its why you wanted to use the echo service to see what the request from netsuite looks like
@raghav if you really only wanted a parser, you can use something like graphql-tag
expect to learn how how to use a javascript bundler like browserify or webpack since parsers tend to use graphql, which itself does not support amd
r
thanks, will look into these.