没有不值得去解决的问题,也没有不值得去学习的技术!

Executing Multiple Mutations in a Single HTTP Request Within a GraphQL Mutation

The plan is to execute multiple Mutations within a single HTTP request. Reference: https://graphql.cn/learn/queries/#aliases , using aliases

1. In a GraphQL Mutation, only one Mutation is currently executed within a single HTTP request. See Figure 1.

In a GraphQL Mutation, only one Mutation is currently executed within a single HTTP request
Figure 1
GraphQL

mutation UploadThemeAsset($input: ThemeAssetUploadInput!) {
	onlineStoreThemeAssetUpload(input: $input) {
		themeAsset {
			id
			themeId
			value
			key
			publicUrl
			mimeType
			checksum
			category
			warnings
			createdAt
			updatable
			deletable
			renameable
			updatable
		}
	}
}

JSON

{
	"input": {
		"themeId": "{{themeId}}",
		"key": "assets/js/1.js",
		"value": "string"
	}
}

JSON

{
  "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. When the number of HTTP requests per unit of time is too high, it triggers API rate limiting. See Figure 2.

When the number of HTTP requests per unit of time is too high, it triggers API rate limiting
Figure 2

3. The plan is to execute multiple Mutations within a single HTTP request. Reference: https://graphql.cn/learn/queries/#aliases , using aliases. See Figure 3.

The plan is to execute multiple Mutations within a single HTTP request. Reference: https://graphql.cn/learn/queries/#aliases , using aliases
Figure 3
GraphQL

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
}


JSON

{
	"input1": {
		"themeId": "{{themeId}}",
		"key": "assets/js/1.js",
		"value": "string"
  },
  "input2": {
		"themeId": "{{themeId}}",
		"key": "assets/js/2.js",
		"value": "string"
	}
}

JSON

{
  "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
      }
    }
  }
}

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系