Error when trying to use CLI to update Lambdas

I am getting an error when i try to push our lambda file from the slash-graphql CLI.

The error im getting is:

TypeError: first argument must be a string or instance of Error

Here is the command i am running:

slash-graphql update-lambda -e https://ENDPOINT.aws.cloud.dgraph.io/graphql -f ./lambdaDgraph/_final.js

which is just like the docs here recommend from what i can tell. I have tried it with and without a token.

I also am able to update the schema file with no problem, so I know I am able to connect successfully.

Any ideas on that?

1 Like

pinging @gja

Hello @pbassham,

I just tried the same command and it seems to be working for me. Can you run npm update -g slash-graphql once and try again?

EDIT: I get the same error when I provide a wrong Slash GraphQL endpoint. Can you verify yours?

I did that. I think the endpoint connection is fine because the response this time included

Successfully refreshed token

And then they same error.

I got this to work finally by logging out and logging back in.

I assume that was necessary after the update?

2 Likes

Logout and login is not really a mandate after updates. Looks like a rare case. I and a colleague could not reproduce this. Will keep an eye on this problem and solution. Thank you so much for sharing the solution.

I still have my terminal open where it went from failure to success, so here it is.

I made a new token just before this and used it too, but i am not really clear on what the purpose of the token is either actually.

Using the token alone didnt succeed, and after logged in, it doesnt seem the token is necessary. So, when is the token encessary?

I am having this same problem:

npm i -g slash-graphql

then

slash-graphql login MYEMAIL MYPASSWORD

then

slash-graphql update-lambda -e MYENDPOINT -f MY-LAMBDAS-JSFILE

and I get this error:

TypeError: first argument must be a string or instance of Error

So I try logging out like so:

slash-graphql logout

and I get this:

Error: Could not log you out. Please try logging in with `slash-graphql login`, then try invalidating all clients with `slash-graphql logout -a

so I try that:

slash-graphql logout -a

and it HANGS, no response after minutes without pressing CTRL + C…


I should note that slash-graphql update-lambda does not work with a token, and requires a login in the first place.

Now, I just need to logout. No idea how to do that. Re-logging-in does nothing. I suspect this is an issue on Windows, and may work fine in a Unix environment.

1 Like

I am having the same problem ever since the updates in slash graphql… There are two problems as I see it:

  1. update lambda is returning this error TypeError: first argument must be a string or instance of Error when I seem to be properly logged in and passing a valid enndpoint

  2. update lambda should work without having to login by passing an admin token with the -t arg, and it does not, though it didn’t before the update either

1 Like

The March 25 update broke some things in the CLI (including aforementioned admin token). We’re currently evaluating the position of the CLI. There may be other, better ways to interact with Dgraph Cloud/Slash and we’re exploring the alternatives. More to come

4 Likes

We like our versioned workflow with git. Hopefully that isn’t going to be made more difficult.

4 Likes

I agree with @pbassham and throw my input into the mix - having the CLI is very useful for deployment workflows and CI actions, hope the outcome is similarly useful and easy to use for things like that

1 Like

Maybe a GraphQL Dgraph Cloud admin endpoint is coming? Just guessing. Each db already has a GraphQL admin endpoint and it would make sense if that was extended to do more of the Dgraph Cloud Management admin tasks as well. It already can handle schema pushes, other backend tasks shouldn’t be that far fetched.

Hi,

When trying:
slash-graphql update-lambda -e $npm_package_config_url --file=dist/main.js

Am getting below error.

TypeError: first argument must be a string or instance of Error

Tried login and logout as suggested but no luck. What am i missing?

Thanks

You’ll need to update to use the new cloud admin endpoint.

Here is a working script that we are using via a husky powered git hook.


const fetch = require('node-fetch')
const fs = require('fs')

async function updateSlashLambdas() {
  try {
    fs.readFile('./DgraphLambdas/_final.js', async function (err, data) {
      if (err) return console.error(err)
      const lambdaScript = data.toString('base64')
      
      const updateLambdasQuery = `mutation UpdateDeployment($updateDeploymentInput: UpdateDeploymentInput!) {
          updateDeployment(input: $updateDeploymentInput)
      }
      `
      const response = await fetch(`https://cerebro.cloud.dgraph.io/graphql`, {
        headers: {
          'Content-Type': 'application/json',
          Authorization:
            'Bearer <TOKEN>',
        },
        method: 'POST',
        body: JSON.stringify({
          query: updateLambdasQuery,
          variables: {
            updateDeploymentInput: {
              uid: '0x2…',
              lambdaScript: lambdaScript,
            },
          },
        }),
      })
      const json = await response.json()
      if (json.errors) {
        throw json.errors
      }
      
      console.log(JSON.stringify(json))
    })
  } catch (error) {
      console.log(error);
  }
}
updateSlashLambdas()

1 Like

Thanks @pbassham

The script is working perfectly.

NB: To get the ‘Bearer ’ you have to execute the login method using your slash-graphql credentials on the cloud admin endpoint

https://cerebro.cloud.dgraph.io/graphql

1 Like