-
Notifications
You must be signed in to change notification settings - Fork 731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to create Query.Data without getting it through the AppoloClient? #51
Comments
I'd be interested in hearing more about how people intend to use query results with tests, and see how we can make this easier. It may make sense to also generate memberwise constructors for these structs. For now, the easiest way is probably to create a |
Thanks for the quick response.
And yes generating memberwise constructors would be much more convenient than having to parse json to create a struct. |
@Nuke-: Make sure to update to the most recent version, because |
That made it work. Thanks. |
I'm also having the error saying that import Foundation
import Apollo
class MyGraphQL {
func getInbox() {
guard let rootObject = json(forFileName: "inbox") else { return }
let query = InboxQuery()
let response = GraphQLResponse(operation: query, body: rootObject)
let (result, _) = try response.parseResult().await()
}
private func json(forFileName fileName: String) -> JSONObject? {
guard let file = Bundle.main.path(forResource: fileName, ofType: "json"),
let string = try? String(contentsOfFile: file, encoding: .utf8),
let data = string.data(using: .utf8),
let object = try? JSONSerialization.jsonObject(with: data, options: []) else {
return nil
}
return object as? JSONObject
}
} |
@jbouaziz: You should be able to use |
It works thanks @martijnwalraven. For those who come here, the exact method name is |
@jbouaziz: No, the snapshot constructor is not actually meant to be public! It doesn't do any type checking / conversion and can lead to crashes. So you should use |
My bad, it didn't show up in the autocompletion. Thanks! |
I'm using 0.8 version and |
@marinofelipe You shouldn't have to use |
@martijnwalraven Thanks for your fast reply. I can't initialise |
If this protection have to exist, what do you think about making |
With Apollo Codegen an API.swift file is generate with contains the data structs.
But how can you create a struct without getting it through the AppoloClient as there is only an init which accepts a GraphQLResultReader?
I'm looking to create the data in a unit testing scenario without having to get it through the AppoloClient.
I tried creating a mock AppoloStore or a GraphQLResultReader but that doesn't seem possible as the init or other methods are inaccessible.
Take for example following API.swift file.
How would you create a Channel?
The text was updated successfully, but these errors were encountered: