diff --git a/package.json b/package.json index 46a02d6c..82fe3ca2 100644 --- a/package.json +++ b/package.json @@ -70,12 +70,14 @@ "atob": "2.1.2", "axios": "^1.5.1", "csrf": "^3.0.4", + "graphql-request": "^7.1.2", "jsonwebtoken": "^9.0.2", "query-string": "^6.12.1", "rsa-pem-from-mod-exp": "^0.8.4", "winston": "^3.1.0" }, "devDependencies": { + "@snyk/protect": "^1.657.0", "btoa": "^1.2.1", "chai": "^4.1.2", "chai-as-promised": "^7.1.1", @@ -87,8 +89,7 @@ "nock": "^9.2.3", "nyc": "^15.0.1", "prettier": "^2.0.5", - "sinon": "^9.0.2", - "@snyk/protect": "^1.657.0" + "sinon": "^9.0.2" }, "snyk": true } diff --git a/sample/graphqlClient.js b/sample/graphqlClient.js new file mode 100644 index 00000000..9ef48ebf --- /dev/null +++ b/sample/graphqlClient.js @@ -0,0 +1,93 @@ +//Instructions: +// Run the program using this command from the terminal: +// node grapqlClient.js + +// Install npm package +// npm install graphql-request + +'use strict'; + +//Import necessary modules +const { GraphQLClient, gql } = require('graphql-request'); + +//constants +const GRAPHQL_API_ENDPOINT = "https://qb-sandbox.api.intuit.com/graphql"; +const ENV = "Sandbox"; +const API_TOKEN = ""; + +const client = new GraphQLClient(GRAPHQL_API_ENDPOINT, { + headers: { + Authorization: `Bearer ${API_TOKEN}`, // Optional: If your API requires authentication + }, + }); + + //define your GraphQL query or mutation + const query = gql` + query RequestEmployerInfo { + payrollEmployerInfo { + employerCompensations { + edges { + node { + id + alternateIds { + id + } + name + type { + key + value + description + } + } + } + } + } +} +`; + +//Handle input variables +const queryWithVariables = gql` +query getEmployeeCompensationById { + payrollEmployerInfo { + employerCompensations (filter: {$employeeId: ID!}){ + edges { + node { + id + alternateIds { + id + } + name + } + } + } + } +} +`; +const variables = { employeeId: "3" }; + +//function to call the query with no variables +async function fetchData() { + try { + const data = await client.request(query); + console.log(JSON.stringify(data, null, 2)); + } catch (error) { + console.error('Error fetching data:', error); + } + } + + async function fetchDataWithVariables() { + try { + const data = await client.request(queryWithVariables, variables); + console.log(JSON.stringify(data, null, 2)); + } catch (error) { + console.error('Error fetching data:', error); + } + } + +//run the query (one without input variable) +fetchData(); + +//run the query (one with input variable) +//fetchDataWithVariables(); + +