Hello Prefect Community & Support. Having an i...
# ask-community
j
Hello Prefect Community & Support. Having an issue interacting with Get Projects GraphQL endpoint on Prefect IO. My request:
Copy code
query {
  project(limit: 10, offset: 0) {
    name
  }
}
My response:
Copy code
{
  "errors": [
    {
      "message": "Response not successful: Received status code 400",
      "locations": [],
      "path": [
        "project"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "name": "ServerError",
          "response": {
            "size": 0,
            "timeout": 0
          },
          "statusCode": 400,
          "result": {
            "errors": [
              {
                "extensions": {
                  "path": "$.selectionSet.project",
                  "code": "validation-failed"
                },
                "message": "field \"project\" not found in type: 'query_root'"
              }
            ]
          }
        }
      }
    }
  ],
  "data": null,
  "extensions": {
    "tracing": {
      "version": 1,
      "startTime": "2020-05-26T00:41:36.814Z",
      "endTime": "2020-05-26T00:41:36.819Z",
      "duration": 4909820,
      "execution": {
        "resolvers": [
          {
            "path": [
              "project"
            ],
            "parentType": "Query",
            "fieldName": "project",
            "returnType": "[project!]!",
            "startOffset": 88849,
            "duration": 4807789
          }
        ]
      }
    }
  }
}
I've tried with both JavaScript (using apollo-link) and also CLI using curl. Both give same result.
n
Hi @jars! How are you passing your API token? And what's the endpoint you're querying?
j
Hello @nicholas. Like this w/ JS using https://api.prefect.io (actually, I've tried various urls, including this one, adding
/graphql
and also adding
graphql/alpha
after inspecting network requests in the Interactive API dashboard. But, none seem to work:
Copy code
const link = new HttpLink({
  uri,
  fetch,
  headers: { authorization: `Bearer ${PREFECT_CLOUD_TOKEN}` }
});
And like this with curl:
Copy code
curl -X POST -H "Content-Type: application/json" -H "authorization: Bearer <token here>" -d @payload.json <https://api.prefect.io>
When I used @payload.json in the curl command, I copy pasted the exact POST request payload from the Interactive API UI's network requests panel in Chrome... in order to make sure it was AST transformed. It wasn't the raw query.
Happy to post the full nodejs code, if helpful. Or email to you.
n
Thanks Jordan, would you mind trying it with
Authorization
instead of
authorization
against
<https://api.prefect.io/graphql>
?
(just trying to rule that one out)
j
sure sec
same thing @nicholas
n
Ok cool, just wanted to make sure. One sec, let me look into it
j
@nicholas, it's literally this file:
Copy code
const { execute, makePromise } = require('apollo-link');
const { HttpLink }             = require('apollo-link-http');
const gql                      = require('graphql-tag');
const fs                       = require('fs');
const fetch                    = require('node-fetch');

require('dotenv').config();

const uri = '<https://api.prefect.io/graphql>';

const { PREFECT_CLOUD_TOKEN } = process.env;

const link = new HttpLink({
  uri,
  fetch,
  headers: { Authorization: `Bearer ${PREFECT_CLOUD_TOKEN}` }
});

const query = 'query { project(limit: 10, offset: 0) { name } }';

const operation = { query: gql(query), variables: {} };

(async () => {

  try {

    const data = await makePromise(execute(link, operation));

    console.log(JSON.stringify(data));

  }
  catch (err) {

    console.log('failure');
    console.log(err);

  }

})();
if you want to run it... just:
Copy code
mkdir api_issue_may_25
cd api_issue_may_25
npm init -y
npm i --save apollo-link apollo-link-http graphql-tag node-fetch
<dump above file into index.js in this directory>
PREFECT_CLOUD_TOKEN=<token here> node index.js
n
Hm, your code seems to work for me
j
hmmmmm
I am using a USER token type, is that correct?
n
Ah no, you'll need to use a
TENANT
-scoped token for that operation
j
haha, well, I suppose that would do it.
n
Let me know if that works, if not we can keep troubleshooting 🙂
j
I will try it. One moment. I appreciate your fast support. Maybe an opportunity for a clearer error response, if this is the case? 🙂
success ✔️ !!
n
Nice!
j
thanks again @nicholas!!
n
I'll pass that along to the Cloud team, I'm sure that can be improved 🙂
Np!
j
@nicholas, some new errors I cannot seem to figure out. Given the above, could you try switching out the limit and offsets to be a query like this instead?
Copy code
query {
  project(order_by: { name: asc }) {
    name
  }
}
This is straight out of the Prefect docs. I am getting 403 Forbidden errors... But If I remove the order by, it returns successfully:
Copy code
query {
  project {
    name
  }
}
I'm using a Tenant token. Seems strange that asking for the results to be ordered is a Access Denied issue.
n
Hm @jars that also seems to work for me - which method are you using for that?
j
Thanks @nicholas. Sorry, what do you mean by method?
HTTP method? It's a POST Local JS script, exactly as above.
le sigh, it works today.
n
Potentially a network issue then, feel free to start a new thread if you see it again though!
j
thank you @nicholas.
😄 1