在 GraphQL Mutation 中,在同一次 HTTP 请求中,执行多个 Mutation 的实现
1、在 GraphQL Mutation 中,在同一次 HTTP 请求中,现在仅执行了一个 Mutation。如图1
mutation UploadThemeAsset($input: ThemeAssetUploadInput!) { onlineStoreThemeAssetUpload(input: $input) { themeAsset { id themeId value key publicUrl mimeType checksum category warnings createdAt updatable deletable renameable updatable } } }
{ "input": { "themeId": "{{themeId}}", "key": "assets/js/1.js", "value": "string" } }
{ "data": { "onlineStoreThemeAssetUpload": { "themeAsset": { "id": "346186", "themeId": "98ad1110-014d-4a61-bbb4-d74bc4ed30f7", "value": "string", "key": "assets/js/1.js", "publicUrl": null, "mimeType": "text/plain", "checksum": "ecb252044b5ea0f679ee78ec1a12904739e2904d", "category": "asset", "warnings": [], "createdAt": "2023-03-14 17:36:36", "updatable": false, "deletable": false, "renameable": false } } } }
2、当单位时间内 HTTP 请求数量过多时,会触发接口的限流。如图2
3、计划在同一次 HTTP 请求中,执行多个 Mutation。参考:https://graphql.cn/learn/queries/#aliases ,使用别名。如图3
mutation UploadThemeAsset($input1: ThemeAssetUploadInput!, $input2: ThemeAssetUploadInput!) { themeAssetUpload1: onlineStoreThemeAssetUpload(input: $input1) { themeAsset { ...themeAssetFields } } themeAssetUpload2: onlineStoreThemeAssetUpload(input: $input2) { themeAsset { ...themeAssetFields } } } fragment themeAssetFields on ThemeAsset { id themeId value key publicUrl mimeType checksum category warnings createdAt updatable deletable renameable updatable }
{ "input1": { "themeId": "{{themeId}}", "key": "assets/js/1.js", "value": "string" }, "input2": { "themeId": "{{themeId}}", "key": "assets/js/2.js", "value": "string" } }
{ "data": { "themeAssetUpload1": { "themeAsset": { "id": "346186", "themeId": "98ad1110-014d-4a61-bbb4-d74bc4ed30f7", "value": "string", "key": "assets/js/1.js", "publicUrl": null, "mimeType": "text/plain", "checksum": "ecb252044b5ea0f679ee78ec1a12904739e2904d", "category": "asset", "warnings": [], "createdAt": "2023-03-14 17:36:36", "updatable": false, "deletable": false, "renameable": false } }, "themeAssetUpload2": { "themeAsset": { "id": "346187", "themeId": "98ad1110-014d-4a61-bbb4-d74bc4ed30f7", "value": "string", "key": "assets/js/2.js", "publicUrl": null, "mimeType": "text/plain", "checksum": "ecb252044b5ea0f679ee78ec1a12904739e2904d", "category": "asset", "warnings": [], "createdAt": "2023-03-14 18:04:55", "updatable": false, "deletable": false, "renameable": false } } } }
近期评论