3

How to run Api request in Magento's newly introduced feature Graphql. I have gone through some of the documents. In my local environemnt, So far I have installed ChromeiQL extension from chrome version 1.0.

The site is in developer mode.

In the search bar i have entered the

http:magento-root-url/graphql

After that i have tried to get the product by filtering price, so i have executed the following query for that,

{
  products (
    filter: {
      price: {
        gt: "1"
      }
    }
  ) 
  {
    items {
        name
    }
  }
}

But it throws following error,

TypeError: Failed to fetch.

Do I need to perform any other Configurations changes before the request is made.

Kindly help me with this..

enter image description here

8
  • Can you please upload your schema.graphqls file? Jul 26, 2019 at 5:22
  • i didn't create schema.graphqls file .. Do we need to create ?
    – aravind
    Jul 26, 2019 at 5:36
  • Yes. I think you need to create for price filter. Jul 26, 2019 at 5:48
  • Strange ..!! I got output proper by your query which you mentioned in question. Jul 26, 2019 at 5:57
  • Do we need to make any configuartion changes in admin panel?
    – aravind
    Jul 26, 2019 at 6:01

3 Answers 3

2

Not sure about your actual problem. But, it's working fine. Just follow this step :

{
  products (
    filter: {
      price: {
        gt: "40"
        lt: "50"
      }
    }
  ) 
  {
    items {
        name
    }
  }
}

Copy this above query at left side (In query variable part) and just execute "Execute-Query" button (Ctrl + Enter)

enter image description here

7
  • Thanks for your answer ...still the same issue..Does this work in ubuntu ? I am using ubuntu
    – aravind
    Jul 26, 2019 at 8:24
  • Yes. I'm also use ubuntu. Jul 26, 2019 at 8:24
  • Then i don't know why the results are not coming..What is your version?
    – aravind
    Jul 26, 2019 at 8:26
  • It's 1.0 ............ Jul 26, 2019 at 8:32
  • mine also 1.0..
    – aravind
    Jul 26, 2019 at 8:36
1

Make sure you entered http:// yourdomain.com/graphql

I got the error TypeError: Failed to fetch. because I put mydomain.com/graphql without http://

Hope it helps

0

You can try below sample request.

{
  products(
    filter: {
      sku: {
        like: "24-MB%"
      }
      price: {
        lt: "50"
      }
    }
  )
  {
    items {
      sku
   }
}
5
  • still same issue..Whatever command i execute it throws same error
    – aravind
    Jul 25, 2019 at 12:06
  • your storefront working well ? Jul 25, 2019 at 12:08
  • yes i can access the site in frontend ..Only graphql issue..Look at my attached image
    – aravind
    Jul 25, 2019 at 12:11
  • ok. can you try after enabling developer mode ? Jul 25, 2019 at 12:12
  • it is in developer mode only.. I performing in my local environment
    – aravind
    Jul 25, 2019 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.