• GraphiQL温故


    • 温故GraphiQL学习指南相关笔记,加深对GraphiQL基本类型、查询、突变、订阅的理解

    • 结合项目实际理解对象的传递

    mutation CreateReviewForEpisode($episode: Episode!, $review: ReviewInput!) {
      createReview(episode: $episode, review: $review) {
        stars
        commentary
      }
    }
    
    let review = ReviewInput(stars: 5, commentary: "This is a great movie!")
    apollo.perform(mutation: CreateReviewForEpisodeMutation(episode: .jedi, review: review))
    

    文件上传

    mutation UploadFile($file:Upload!) {
        singleUpload(file:$file) {
            id
        }
    }
    
    // Create the file to upload
    guard
      let fileURL = Bundle.main.url(forResource: "a", 
                                    withExtension: "txt"),
      let file = GraphQLFile(fieldName: "file",   
                             originalName: "a.txt", 
                             mimeType: "text/plain", // <-defaults to "application/octet-stream"
                             fileURL: fileURL) else {
        // Either the file URL couldn't be created or the file couldn't be created.
        return 
    }
    
    // Actually upload the file
    client.upload(operation: UploadFileMutation(file: "a"), // <-- `Upload` is a custom scalar that's a `String` under the hood.
                  files: [file]) { result in 
      switch result {
      case .success(let graphQLResult):
        print("ID: (graphQLResult.data?.singleUpload.id)")
      case .failure(let error):
        print("error: (error)")
      }
    }
    • 有效上传
    mutation AvatarUpload($userID: GraphQLID!, $file: Upload!) {
      id
    }
    • 无效上传
    // Assumes AvatarObject(userID: GraphQLID, file: Upload) exists
    mutation AvatarUpload($avatarObject: AvatarObject!) {
      id
    }
    • note:对象需要使用具体文件,如果上传文件数组需要同名,数量也得对应
    query HeroAndFriends($episode: Episode) {
      hero(episode: $episode) {
        name
        ...HeroDetails
        friends {
          ...HeroDetails
        }
      }
    }
    
    fragment HeroDetails on Character {
      name
      appearsIn
    }
    
    
    func configure(with heroDetails: HeroDetails?) {
      textLabel?.text = heroDetails?.name
    }
    
    
    apollo.fetch(query: HeroAndFriendsQuery(episode: .empire)) { result in
      guard let data = try? result.get().data else { return }
      print(data.hero?.name) // Luke Skywalker
      print(data.hero?.appearsIn) // WON'T WORK
      print(data.hero?.fragments.heroDetails.appearsIn) // [.newhope, .empire, .jedi]
      print(data.hero?.friends?.flatMap { $0?.fragments.heroDetails.name }.joined(separator: ", ")) // Han Solo, Leia Organa, C-3PO, R2-D2
    }
    
    
    cell.configure(with: hero?.fragments.heroDetails)
  • 相关阅读:
    异步文档树解决方案
    兼容IE低版本的文件上传解决方案
    CentOS-常用命令(版本:7.x)
    搭建Nexus3私服(含使用说明,支持CentOS、Windows)
    CentOS-搭建MinIO集群
    GitLab升级(yum安装版v11.11.8~12.0.12)
    yum安装GitLab-v11.11.8(git私服)
    Docker中容器的备份和恢复(可迁移)
    Nexus3配置yum私服
    局域网连接数据慢的方法汇总
  • 原文地址:https://www.cnblogs.com/liuxiaokun/p/12676841.html
Copyright © 2020-2023  润新知