DEV Community

Discussion on: Ruby on Rails GraphQL API Tutorial: From 'rails new' to First Query

Collapse
 
otangvinhduong profile image
oTangVinhDuong • Edited

Hi I have the same error as Jose-Xu, Don't know when you made it, have you tried again?
dev.to/qz135636665908/comment/oo7f
quote:
"Hi Isa, I actually found my issues, as I typed something wrong in my query_type.rb file. Thanks for made it clear that I should not have expect localhost:3000/graphql to work in the browser!"

I don't know what error he made in query_type.rb file but I checked it very well and I got it right!
can you check this problem ? thanks

Collapse
 
isalevine profile image
Isa Levine

Hi oTangVinhDuong! If I'm not mistaken, I believe Jose-Xu's problem was trying to access localhost:3000/graphql in a browser.

Since GraphQL relies on sending POST requests only, you will need to use a tool like Insomnia, Postman, or graphiql to view the query results.

To double-check everything is working, I just used Insomnia to send a POST request to localhost:3000/graphql/ using a GraphQL body with the following query:

query {
    allOrders {
        id
        description
        total      
        successfulPayments {
            id
            amount
            status
        }
    }
}

I also confirmed that the query_type.rb file I used just now matches what is above--this is the code I just ran:

module Types
  class QueryType < Types::BaseObject
    field :all_orders, [Types::OrderType], null: false

    def all_orders
      Order.all
    end
  end
end

Let me know if you're still having issues, and I'll try to help as best I can! :)