Yelp / yelp-fusion

Yelp Fusion API
https://yelp.com/developers
MIT License
403 stars 394 forks source link

Error 400 no generic error #403

Closed mrjackyliang closed 6 years ago

mrjackyliang commented 6 years ago

Overview

Description

Trying to do a business search, but get's error 400 instead with no reason why.

Endpoint

Fusion Search API

Parameters or Sample Request

this.client = new ApolloClient({
    uri: 'https://api.yelp.com/v3/graphql',
    request: (operation) => {
        operation.setContext({
            headers: {
                Authorization: `Bearer ${API_KEY}`,
                "Content-Type": 'application/graphql',
            }
        })
    },
    cache: new InMemoryCache(),
});

Response

[Network error]: Error: Response not successful: Received status code 400

Extra information

Error information from remote js debugger (react native)

teekwak commented 6 years ago

Hi there,

400 looks like maybe there is a typo somewhere in the request you are making. Can you upload the query you are making to our GraphQL endpoint?

mrjackyliang commented 6 years ago

This is the query we're making. We also tried it in a test, and that worked.

{
  search(location: "san francisco") {
    total
    business {
      name
    }
  }
}
teekwak commented 6 years ago

Query looks good to me. Just tested myself as well via command-line.

I see that you are using React-Native. Correct me if I am wrong, but your code snippet seems to be creating the ApolloClient in a React component. If so, this will cause a CORS error when the ApolloClient makes the fetch request, which we do not currently support (see https://github.com/Yelp/yelp-fusion/issues/64 for workarounds to this issue).

mrjackyliang commented 6 years ago

How do we go forward with that?

mrjackyliang commented 6 years ago

I found that the request isn’t being created inside a React component.

The component calls the function which the function loads the class via an instance.