Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to invoke javascript code from handler/odata/schemaHeaders? #5170

Open
cmcconomyfwig opened this issue Feb 21, 2023 · 3 comments
Open

How to invoke javascript code from handler/odata/schemaHeaders? #5170

cmcconomyfwig opened this issue Feb 21, 2023 · 3 comments

Comments

@cmcconomyfwig
Copy link

cmcconomyfwig commented Feb 21, 2023

Following advice I saw on another issue here, I attemped to use the following configuration:

sources:
  - name: Microsoft Graph
    handler:
      odata:
        endpoint: https://MYURL.crm.dynamics.com/api/data/v9.2/
        batch: multipart
        expandNavProps: true
        operationHeaders: ./introspection-headers.js
        schemaHeaders: ./introspection-headers.js

with ./introspection-headers.js having,

const msal = require('@azure/msal-node');

// async function get_dynamics_token() {
exports.default = async () =>  {
    const authConfig = {
      auth: {
        clientId: 'CLIENT',
        authority: 'https://login.windows.net/MYGUID',
        clientSecret: 'CLIENTSECRET',
      }
    };
  
    const cca = new msal.ConfidentialClientApplication(authConfig);
    const ccRequest = {scopes: ['https://MYURL.api.crm.dynamics.com/.default']};
    const res = await cca.acquireTokenByClientCredential(ccRequest);
    return { "Authorization": `Bearer ${res.accessToken}` }
   }

However, this config yields the following issue:

⚠️ 🕸️  Mesh - config Configuration file is not valid!
⚠️ 🕸️  Mesh - config This is just a warning! It doesn't have any effects on runtime.
⚠️ 🕸️  Mesh - config Error: must be object

This error goes away if I provide a static Authorization directly (but of course I need to update this dynamically!)

So it appears we cannot yet invoke javascript to return dynamic output for the operation and schema headers, unless I missed something.

How can I set myself up to dynamically invoke javascript when I pull the schema and when I query?

(Added context - here is my package.json)

{
  "name": "graphql-mesh",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@azure/msal-node": "^1.15.0",
    "@graphql-mesh/cli": "^0.82.23",
    "@graphql-mesh/odata": "^0.22.13",
    "graphql": "^16.6.0"
  }
}
@xmlking
Copy link

xmlking commented Mar 2, 2023

is JS supported for operationHeaders/schemaHeaders ? I also have same requirement

@xmlking
Copy link

xmlking commented Mar 9, 2023

@Urigo can you please confirm this feature is available or deprecated? I am seeing following error with latest dependencies.

image

image

image

This was referenced Apr 30, 2024
This was referenced May 7, 2024
@imyixiao
Copy link

@ardatan @Urigo can you please confirm the status of this introspection-headers.js? we do need this for generating jwt tokens dynamically

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants