在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):spring-media/GraphQLicious开源软件地址(OpenSource Url):https://github.com/spring-media/GraphQLicious开源编程语言(OpenSource Language):Swift 90.3%开源软件介绍(OpenSource Introduction):GraphQLiciousGraphQLicious is a swift component that provides an intuitive and convenient way to build GraphQL queries and convert them easily to String representations. [![iOS 8] (https://img.shields.io/badge/iOS%208%2B%20%7C%20MacOS%20X%2B%20%7C%20TV%20OS%20%7C%20Watch%20OS%202%2B-Compatible-brightgreen.svg)] () ContentsInstallationCarthage
CocoaPods
SubmoduleIf you don't use CocoaPods, you can still add
ManualYou can directly drag and drop the needed files into your project, but keep in mind that this way you won't be able to automatically get all the latest features. UsageQueryLet's assume, we have the id of an article and we want to have the Our graphQL query for that will look like this: query {
test: content(id: 153082687){
...contentFields
}
}
fragment contentFields on Content {
headline,
body,
image(role: "opener", enum: [this, that]){
...imageContent
}
}
fragment imageContent on Image {
id
url
}
fragment urlFragment on Image {
url (ratio: 1, size: 200)
}
First, let's create a let imageContent = Fragment(
withAlias: "imageContent",
name: "Image",
fields: [
"id",
"url"
]
) Next, let's embed the enum customEnum: String, ArgumentValue {
case This = "this"
case That = "that"
private var asGraphQLArgument: String {
return rawValue // without quotes
}
}
let customEnumArgument = Argument(
key: "enum",
values: [
customEnum.This,
customEnum.That
]
) let imageContentRequest = Request(
name: "image",
arguments: [
Argument(key: "role", value: "opener"),
customEnumArgument
],
fields: [
imageContent
]
) So now we have a Request with an embedded Fragment. Let's go one step further. let articleContent = Fragment(
withAlias: "contentFields",
name: "Content",
fields: [
"headline",
"body",
imageContentRequest
]
) Finally, we put everything together as a let query = Query(request: Request(
withAlias: "test",
name: "content",
arguments: [
Argument(key: "id", values: [153082687])
],
fields: [
articleContent
]),
fragments: [articleContent, imageContent]
) All we have to do now is to call
MutationLet's assume, we want to change our username and our age in our backend and we want to have the new name and age back to make sure everything went right. Let's assume further, our server provides a mutating method Our graphQL query for that will look like this: mutation myMutation {
editMe(
name: "joe",
age: 99
)
{
name,
age
}
} Let us first create the actual mutating function. We can use a let mutatingRequest = Request(
name: "editMe",
arguments: [
Argument(name: "name", value: "joe"),
Argument(name: "age", value: 99)
],
fields: [
"name",
"age"
]
) Finally, we put everything together as a
let mutation = Mutation(
withAlias: "myMutation",
mutatingRequest: mutatingRequest
) After we've done that we can create the request. print(mutation.create()) Breaking changes
From |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论