Skip to content

Instantly share code, notes, and snippets.

View chandan-0's full-sized avatar
🏠
Work from home

Chandan chandan-0

🏠
Work from home
View GitHub Profile
//
// ViewController.swift
// Learning GraphQL
//
// Created by Chandan on 30/01/22.
//
import UIKit
class ViewController: UIViewController {
@chandan-0
chandan-0 / LearningGraphQLAPI.swift
Last active April 30, 2024 14:46
Mutation API
func addMeasurement(id: String, measurement: ClientMeasurementRequest) -> Future<GraphQLResult<AddMeasurementMutation.Data>, Error> {
let promise = Promise<GraphQLResult<AddMeasurementMutation.Data>, Error>()
Network.shared.apollo.perform(mutation: AddMeasurementMutation(client_id: id, measurementsRequest: measurement)) { response in
switch response.result {
case .success(let graphqlResult):
promise.success(graphqlResult)
case .failure(let error):
promise.failure(error)
}
}
@chandan-0
chandan-0 / API.swift
Created April 26, 2022 01:21
Muation is generated in API.Swift
public final class AddMeasurementMutation: GraphQLMutation {
/// The raw GraphQL definition of this operation.
public let operationDefinition: String =
"""
mutation addMeasurement($client_id: String!, $measurementsRequest: ClientMeasurementRequest!) {
addMeasurement(client_id: $client_id, measurementsRequest: $measurementsRequest) {
__typename
id
weight
weightUnit
@chandan-0
chandan-0 / Query.graphql
Created April 26, 2022 01:05
Mutations.
mutation addMeasurement($client_id: String!, $measurementsRequest: ClientMeasurementRequest!) {
addMeasurement(client_id: $client_id, measurementsRequest: $measurementsRequest) {
__typename
id
weight
weightUnit
height
heightUnit
createdAt
}
2022-03-06 17:24:57.018472+0530 Learning GraphQL[92954:10939120] [boringssl] boringssl_metrics_log_metric_block_invoke(151) Failed to log metrics
▿ Optional(Learning_GraphQL.GetCountryQuery.Data.Country(resultMap: ["phone": Optional("91"), "__typename": Optional("Country"), "native": Optional("भारत"), "capital": Optional("New Delhi"), "name": Optional("India"), "code": Optional("IN"), "currency": Optional("INR")]))
▿ some: Learning_GraphQL.GetCountryQuery.Data.Country
▿ resultMap: 7 key/value pairs
▿ (2 elements)
- key: "phone"
▿ value: Optional("91")
- some: "91"
▿ (2 elements)
- key: "__typename"
//
// ViewController.swift
// Learning GraphQL
//
// Created by Chandan on 30/01/22.
//
import UIKit
class ViewController: UIViewController {
//
// LearningGraphQLAPI.swift
// Learning GraphQL
//
// Created by Chandan on 06/03/22.
//
import Foundation
import Apollo
import BrightFutures
query getCountry($id: ID!){
country(code: $id) {
code
name
native
phone
capital
currency
}
}
@chandan-0
chandan-0 / Network.swift
Created March 3, 2022 13:21
Creating Apollo-Client iOS
import Foundation
import Apollo
class Network {
static let shared = Network()
var apollo: ApolloClient {
// The cache is necessary to set up the store, which we're going to hand to the provider
let cache = InMemoryNormalizedCache()
let store = ApolloStore(cache: cache)