Comments (7)
We talked a little about this at the Berlin meetup. As I mentioned there, I'm working on a new version that fixes some issues with GraphQLMap
(among many other changes).
I want to make sure the new design works for your use case as well. Can you tell me more about what you're trying to do? What networking library are you using, how do you integrate with it, and why do you need to use it instead of the default network transport?
from apollo-ios.
I just released version 0.4.0 of Apollo iOS, which includes a redesigned GraphQLMap
that will hopefully solve your issue. You should be able to access query.variables.jsonValue
to get a representation suitable for JSON serialization.
Please give it a try and let me know what you think! (You'll also have to update apollo-codegen to 0.9, but it will warn you if you don't.)
from apollo-ios.
Hey Martijn!
I just updated Carthage :) It looks like I imagined it to be, thanks!
I actually dropped Moya for the GraphQL part since the mindset of static routes felt like contradicting the approach of GraphQL. I will stub and test my view models by stubbing the network transport with fake responses.
I really don't know if there should be a separation of concerns for the network and parsing part, since those are so interconnected. Usually, I test whether my parsing code can deal with bad json, but basically you already handle this automatically. Everything that should go wrong should be network errors :) so I'm happy with how you implemented it!
Thanks for your work!
from apollo-ios.
Good to hear! I agree Maya doesn't add much value here and seems more confusing than helpful.
I'd be interested in hearing more about how you approach testing, to better understand the requirements and to see if there's anything more we could add to make it easier.
Stubbing the network transport is probably the best solution right now, especially if you'd like to test for error conditions. I think you're right and you don't you need to test for bad JSON. The only bad JSON I can think of would be an invalid GraphQL response, probably as a result of a bug in the server library. So you're left with either a network or GraphQL errors to test for.
I'm wondering how adding caching and consistency management (which I'm working on right now) will affect testing. Depending on what you're testing, it may make sense to preload the store with test data for example, instead of stubbing the network transport.
from apollo-ios.
Hey Martijn,
I've now tried and failed to stub a fake NetworkTransport for a query. I tried:
class DetailsQueryStubTransport: NetworkTransport {
func send<Operation : GraphQLOperation>(operation: Operation, completionHandler: @escaping (GraphQLResponse<Operation>?, Error?) -> Void) -> Cancellable {
if operation is DetailsQuery {
completionHandler?(GraphQLResponse(operation: operation, rootObject: JSONObject(dictionaryLiteral: ??))
}
}
}
but I don't really know what to put in there. For me it would be awesome if I could directly stub the a json response string like this:
{
"data": {
"viewer": {
"clip": {
"id": "abcd",
"title": "test title",
"description": null,
"teaserImages": {
"edges": []
}
}
}
}
To make that work you could somehow inject an encoded json response (Data
) that will in turn will call the completion handler with a valid GraphQLOperation.Data
.
Also, I changed the access level of the HTTPNetworkTransport class, to make it easy to subclass and debug, why a request might have gone wrong (easier logging): here
from apollo-ios.
You should be able to just construct a GraphQLResponse
from a Swift-based JSON representation, like this:
let response = GraphQLResponse(operation: query, rootObject: [
"data": [
"hero": ["__typename": "Droid", "name": "R2-D2"]
]
])
(See ParseQueryResponseTests.swift for more examples.)
If you really want to pass in a JSON string instead, you could create a helper method that uses JSONSerialization.jsonObject
to parse the string into a dictionary, something like this:
func jsonObject(string: String) -> JSONObject {
let data = string.data(using: .utf8)!
return (try! JSONSerialization.jsonObject(with: data, options: [])) as! JSONObject
}
from apollo-ios.
I will try that, thanks :)
from apollo-ios.
Related Issues (20)
- apollo-ios-codegen 1.8.0 CustomScalar is 'should not be edited.' HOT 2
- Variables Inside Fragments behaving oddly? HOT 14
- Invalid HTTP upgrade spams the log instead of returning an error HOT 10
- `asXXXXXXX` property on a union never returning `nil` if selection set empty HOT 4
- Cache mutations are somewhat painful to work with HOT 5
- Add PrivacyManifest HOT 1
- Can't Use 2 Different Schemas in same Package HOT 2
- `SelectionSet` Generated Initializers Don't Compile with `self` Parameter HOT 5
- When using apollo-ios-pagination, there is an issue where data is not accurately updated when mutations occur. HOT 1
- Xcode Install CLI fails for versions >=1.8 HOT 11
- Test Issue HOT 1
- Testing author_association
- Process Mutation on a Queue when encountering network errors HOT 2
- WebSocketTransport: detect server side completion message. HOT 4
- Invalid type aliases generated on recursive types HOT 4
- The operation couldn’t be completed. (OSStatus error -9847.) HOT 11
- Cannot convert value of type 'GraphQLNullable<[String]>' to expected argument type '[String?]' HOT 10
- SchemaConfiguration.cacheKeyInfo(for:object:) never called? HOT 5
- Watcher not firing after failure to decode response HOT 2
- Cococapods installation should use download script to fetch CLI instead of using embedded binary
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from apollo-ios.