https://prefect.io logo
Title
j

jars

05/26/2020, 12:44 AM
Hello Prefect Community & Support. Having an issue interacting with Get Projects GraphQL endpoint on Prefect IO. My request:
query {
  project(limit: 10, offset: 0) {
    name
  }
}
My response:
{
  "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

nicholas

05/26/2020, 12:45 AM
Hi @jars! How are you passing your API token? And what's the endpoint you're querying?
j

jars

05/26/2020, 12:48 AM
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:
const link = new HttpLink({
  uri,
  fetch,
  headers: { authorization: `Bearer ${PREFECT_CLOUD_TOKEN}` }
});
And like this with curl:
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

nicholas

05/26/2020, 12:54 AM
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

jars

05/26/2020, 12:58 AM
sure sec
same thing @nicholas
n

nicholas

05/26/2020, 1:02 AM
Ok cool, just wanted to make sure. One sec, let me look into it
j

jars

05/26/2020, 1:02 AM
@nicholas, it's literally this file:
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:
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

nicholas

05/26/2020, 1:14 AM
Hm, your code seems to work for me
j

jars

05/26/2020, 1:16 AM
hmmmmm
I am using a USER token type, is that correct?
n

nicholas

05/26/2020, 1:17 AM
Ah no, you'll need to use a
TENANT
-scoped token for that operation
j

jars

05/26/2020, 1:18 AM
haha, well, I suppose that would do it.
n

nicholas

05/26/2020, 1:19 AM
Let me know if that works, if not we can keep troubleshooting 🙂
j

jars

05/26/2020, 1:19 AM
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

nicholas

05/26/2020, 1:21 AM
Nice!
j

jars

05/26/2020, 1:21 AM
thanks again @nicholas!!
n

nicholas

05/26/2020, 1:21 AM
I'll pass that along to the Cloud team, I'm sure that can be improved 🙂
Np!
j

jars

05/27/2020, 11:29 PM
@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?
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:
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

nicholas

05/28/2020, 1:56 PM
Hm @jars that also seems to work for me - which method are you using for that?
j

jars

05/28/2020, 6:15 PM
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

nicholas

05/28/2020, 6:19 PM
Potentially a network issue then, feel free to start a new thread if you see it again though!
j

jars

05/28/2020, 6:20 PM
thank you @nicholas.
😄 1