Hello, I have been struggling with incorporating Apollo into my employers new app. Smarter people before me have done it with a different app, I have followed docs and successfully downloaded Schema and generated the code for my project. However I am struggling when it comes to actually making a query.
The result I am getting back from apollo is thus:
Result<GraphQLResult, Error>
▿ failure : ResponseCodeError
▿ invalidResponseCode : 2 elements
▿ response : Optional
- some : <NSHTTPURLResponse: 0x60000031f280> { URL: my company gql url } { Status Code: 400, Headers {
“Content-Type” = (
“application/json; charset=utf-8”
);
Date = (
“Wed, 21 Sep 2022 11:24:47 GMT”
);
“Transfer-Encoding” = (
Identity
);
Vary = (
Origin
);
“access-control-allow-credentials” = (
true
);
“x-powered-by” = (
Express
);
} }
▿ rawData : Optional
▿ some : 1310 bytes
- count : 1310
▿ pointer : 0x00007fd0fe06fa00
- pointerValue : 140535591795200
I am confused because if I am able to get the schema and generate the code I feel like I should have everything wired up but I dont understand why I am getting a status code 400 back
Thanks for any suggestions
I recommend using Apollo Studio to verify that the query works as you expect it to with the same headers, etc. If you can get it working there and it’s still failing in your app then try a proxy (like Charles Proxy) so you can log the actual request being sent and compare it.
Hey team! Thanks for the fast responses. Turns out the api url for production is a little different than what I had been plugging in.
I adjusted the api URL to the correct one, and now I am getting a 401 response which I believe means I just need to adjust my headers. Thank you again for your support!
tldr: My 400 response was from hitting my company’s test api url. My fix for this was adjusting to the company’s production api url.
Im going to look into Apollo Studio, from your description it sounds like I can use it to make sure xcode is formatting my queries to match what I see on my company’s playground and honestly that would be so clutch to be able to cross reference this.
Ive just gotten really good at navigating my company’s docs to build queries on the playground website but sometimes I have trouble understanding if xcode is formatting it the right way.
You shouldn’t need to worry about Xcode formatting any of the queries. The generated code will contain everything needed for a query from the schema and operation. The Studio check is helpful to ensure that the query is correct and gets a response. If it works in Studio then yes it’s definitely worthwhile to dig a bit deeper into what’s causing the 400 response in the app.
If you do find a formatting problem please let us know and we’ll look into it.