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

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

mutation CreateReviewForEpisode($episode: Episode!, $review: ReviewInput!) {
  createReview(episode: $episode, review: $review) {
    stars
    commentary
  }
}

apollo.perform(mutation: CreateReviewForEpisodeMutation(episode: .jedi, review: review))

文件上传

mutation UploadFile($file:Upload!) {
    singleUpload(file:$file) {
        id
    }
}

// Create the file to upload
guard
                         fileURL: fileURL) else {
    // Either the file URL couldn't be created or the file couldn't be created.
    return 
}

// Actually upload the file
              files: [file]) { result in 
  switch result {
  case .success(let graphQLResult):
  case .failure(let 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]
}


cell.configure(with: hero?.fragments.heroDetails)

相关文章:

  • 2021-10-24
  • 2021-10-30
  • 2021-04-14
  • 2022-01-24
  • 2021-11-29
猜你喜欢
  • 2021-06-21
  • 2021-06-30
  • 2021-08-15
  • 2021-10-01
  • 2021-07-26
  • 2021-08-24
  • 2021-09-17
相关资源
相似解决方案