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

Cannot query from directus endpoint #4754

Closed
VanjaRadovanovic opened this issue Mar 30, 2021 · 3 comments
Closed

Cannot query from directus endpoint #4754

VanjaRadovanovic opened this issue Mar 30, 2021 · 3 comments

Comments

@VanjaRadovanovic
Copy link

Project details

Directus Version: 9.0.0-rc.51
Environment: production
OS: Linux 5.4.0-67-generic
Node: 10.19.0

I'm using latest installment of Directus and I'm trying to query from graphql endpoint with axios
image

And I'm getting this as a response
image
image

Any idea why is this happening?

@rijkvanzanten
Copy link
Member

You're providing the query wrong in Axios 🙂

https://medium.com/@stubailo/how-to-call-a-graphql-server-with-axios-337a94ad6cf9 has a good example on how to do a GraphQL query request from Axios 👍🏻

@RageBrahimi
Copy link
Contributor

const axios = require('axios');

let data = JSON.stringify({
  query: `query {
    items {
      project {
        title,
        id
      }
    }
  }`,
  variables: {}
});

let config = {
  method: 'get',
  url: 'http://localhost:8055/graphql',
  headers: {
    'Content-Type': 'application/json'
  },
  data: data
};

axios(config)
  .then((response) => {
    console.log(JSON.stringify(response.data));
  })
  .catch((error) => {
    console.log(error);
  });

Code straight from Postman. Or use the link above from @rijkvanzanten

@VanjaRadovanovic
Copy link
Author

VanjaRadovanovic commented Mar 30, 2021

Thanks, I was querying like this for wp-graphql so I though it was the same.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants