jars

    jars

    2 years ago
    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.
    nicholas

    nicholas

    2 years ago
    Hi @jars! How are you passing your API token? And what's the endpoint you're querying?
    jars

    jars

    2 years ago
    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.
    nicholas

    nicholas

    2 years ago
    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)
    jars

    jars

    2 years ago
    sure sec
    same thing @nicholas
    nicholas

    nicholas

    2 years ago
    Ok cool, just wanted to make sure. One sec, let me look into it
    jars

    jars

    2 years ago
    @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
    nicholas

    nicholas

    2 years ago
    Hm, your code seems to work for me
    jars

    jars

    2 years ago
    hmmmmm
    I am using a USER token type, is that correct?
    nicholas

    nicholas

    2 years ago
    Ah no, you'll need to use a
    TENANT
    -scoped token for that operation
    jars

    jars

    2 years ago
    haha, well, I suppose that would do it.
    nicholas

    nicholas

    2 years ago
    Let me know if that works, if not we can keep troubleshooting 🙂
    jars

    jars

    2 years ago
    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 ✔️ !!
    nicholas

    nicholas

    2 years ago
    Nice!
    jars

    jars

    2 years ago
    thanks again @nicholas!!
    nicholas

    nicholas

    2 years ago
    I'll pass that along to the Cloud team, I'm sure that can be improved 🙂
    Np!
    jars

    jars

    2 years ago
    @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.
    nicholas

    nicholas

    2 years ago
    Hm @jars that also seems to work for me - which method are you using for that?
    jars

    jars

    2 years ago
    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.
    nicholas

    nicholas

    2 years ago
    Potentially a network issue then, feel free to start a new thread if you see it again though!
    jars

    jars

    2 years ago
    thank you @nicholas.