问题描述
我想使用 graphQl API。 我知道我们需要使用 http requester 来调用 graphQl。 我需要一些关于使用 dwl 形成突变请求的信息。 我试图访问此服务 https://www.predic8.de/fruit-shop-graphql 下面使用
Launching lib/main.dart on iphone6s in debug mode...
Running Xcode build...
Xcode build done. 5.8s
Failed to build iOS app
Error output from Xcode build:
↳
** BUILD Failed **
Xcode's output:
↳
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
/Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:40:81: error: use of undeclared identifier 'PHAccessLevelAddOnly'
[PHPhotoLibrary requestAuthorizationForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus authorizationStatus) {
^
/Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:40:102: error: use of undeclared identifier 'PHAccessLevelReadWrite'
[PHPhotoLibrary requestAuthorizationForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite handler:^(PHAuthorizationStatus authorizationStatus) {
^
/Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:53:89: error: use of undeclared identifier 'PHAccessLevelAddOnly'
status = [PHPhotoLibrary authorizationStatusForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite];
^
/Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:53:110: error: use of undeclared identifier 'PHAccessLevelReadWrite'
status = [PHPhotoLibrary authorizationStatusForAccessLevel:(addOnlyAccessLevel)?PHAccessLevelAddOnly:PHAccessLevelReadWrite];
^
/Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:71:14: error: use of undeclared identifier 'PHAuthorizationStatusLimited'; did you mean 'PHAuthorizationStatusDenied'?
case PHAuthorizationStatusLimited:
^~~~~~~~~~~~~~~~~~~~~~~~~~~~
PHAuthorizationStatusDenied
In module 'Photos' imported from /Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.h:11:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhonesimulator.platform/Developer/SDKs/iPhonesimulator13.6.sdk/System/Library/Frameworks/Photos.framework/Headers/PHPhotoLibrary.h:22:5: note: 'PHAuthorizationStatusDenied' declared here
PHAuthorizationStatusDenied,// User has explicitly denied this application access to photos data.
^
/Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:71:14: error: duplicate case value 'PHAuthorizationStatusDenied'
case PHAuthorizationStatusLimited:
^
/Users/apple/Developer/Flutter/.pub-cache/hosted/pub.dartlang.org/permission_handler-5.1.0+2/ios/Classes/strategies/PhotoPermissionStrategy.m:67:14: note: prevIoUs case defined here
case PHAuthorizationStatusDenied:
^
6 errors generated.
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
Command CompileSwift Failed with a nonzero exit code
note: Using new build system
note: Building targets in parallel
note: Planning build
note: Constructing build description
Could not build the application for the simulator.
Error launching application on iphone6s.
它抛出了错误的请求 但是在下面使用时
%dw2.0
outputapplication/json
---
{
"query": "mutation(\$input:addCategoryInput!) { addCategory(input:\$input) { name products { name}} }","variables": {
"input": {
"id": 6,"name": "Green Fruits","products": 8
}
}
}
它的工作。 我想使用上述格式。两者都不是有效的请求。 请与我分享您的知识或引导我到正确的博客以供参考。
解决方法
由于此时 GraphQL 不是 supported format for DataWeave,因此您必须自己将查询编写为字符串。但是,您可以使用 DataWeave 为查询创建 POST 请求的正文。
示例:
%dw 2.0
output application/json
---
{
"query": "mutation(\$schedule:PipelineScheduleCreateInput!) { pipelineScheduleCreate(input:\$schedule) { pipelineScheduleEdge { node { label nextBuildAt cronline } } } }","variables": {
"schedule": {
"pipelineID": "UGlwZWxpbmUtLS02MzliNWJjOC0wMGZmLT","cronline": "@midnight","label": "Nightly build"
}
}
}