This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class MyApiCaller { | |
var gotData: Bool = false | |
func getTodos() -> URLSessionDataTask { | |
let url = URL(string: "https://jsonplaceholder.typicode.com/todos") | |
let result: URLSessionDataTask = URLSession.shared.dataTask(with: url!) { [weak self] (data, resp, err) in | |
guard let todos = data else { | |
print("No data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
class MyApiCaller { | |
var gotData: Bool = false | |
func getTodos() -> URLSessionDataTask { | |
let url = URL(string: "https://jsonplaceholder.typicode.com/todos") | |
let result: URLSessionDataTask = URLSession.shared.dataTask(with: url!) { (data, resp, err) in | |
guard let todos = data else { | |
print("No data") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Unicycle { | |
var wheel: Wheel? | |
init() { | |
self.wheel = Wheel(parent: self) | |
} | |
deinit { | |
print ("Unicycle is being deinitialized") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// SwiftUI-Gql | |
// | |
// Created by David Choi on 9/19/20. | |
// | |
import SwiftUI | |
struct ContentView: View { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CoreData | |
import Apollo | |
class GqlClient { | |
static let shared = GqlClient() | |
private(set) lazy var apollo = ApolloClient(url: URL(string: "http://localhost:8000/graphql")!) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Entities.swift | |
// SwiftUI-Gql | |
// | |
// Created by David Choi on 9/19/20. | |
// | |
import Foundation | |
protocol IVehicle { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query GetAllVehicles { | |
getAllVehicles { | |
__typename | |
... on Car { | |
id | |
name | |
wheelCount | |
passengerCount | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { IResolvers } from "apollo-server-express"; | |
import { addCar, getAllVehicles, getCars } from "../dataService"; | |
import { Boat, Car, Truck } from "../types/Entities"; | |
import { GqlContext } from "./GqlContext"; | |
const resolvers: IResolvers = { | |
SearchResult: { | |
__resolveType(obj: any, ctx: GqlContext, info: any) { | |
if (obj.wheelCount && obj.passengerCount) return "Car"; | |
if (obj.wheelCount && obj.maxPayload) return "Truck"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { gql } from "apollo-server-express"; | |
const typeDefs = gql` | |
scalar Void | |
interface IVehicle { | |
id: ID! | |
name: String! | |
desc: String! | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from "react"; | |
import "./App.css"; | |
const GetCars = ` | |
{ | |
getCars { | |
id | |
name | |
passengerCount | |
} |
NewerOlder