From 47007f1658a7c2df70f9cbba55a4fda1c0d8b229 Mon Sep 17 00:00:00 2001 From: dugenkui03 Date: Sat, 4 Sep 2021 16:06:35 +0800 Subject: [PATCH] add GraphQL Calculator --- .../server/graphql-calculator.md | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/content/code/language-support/java-kotlin-android/server/graphql-calculator.md diff --git a/src/content/code/language-support/java-kotlin-android/server/graphql-calculator.md b/src/content/code/language-support/java-kotlin-android/server/graphql-calculator.md new file mode 100644 index 0000000000..7f0dd48ca3 --- /dev/null +++ b/src/content/code/language-support/java-kotlin-android/server/graphql-calculator.md @@ -0,0 +1,64 @@ +--- +name: graphql-calculator +description: A lightweight graphql calculation engine. +url: https://github.com/graphql-calculator/graphql-calculator +github: graphql-calculator/graphql-calculator +--- + +GraphQL Calculator is a lightweight graphql calculation engine, +which is used to alter execution behavior of graphql query. + +Here are some examples on how to use GraphQL Calculator on graphql query. + +```graphql + +query basicMapValue($userIds:[Int]){ + userInfoList(userIds:$userIds) + { + id + age + firstName + lastName + fullName: stringHolder @map(mapper: "firstName + lastName") + } +} + + +query filterUserByAge($userId:[Int]){ + userInfoList(userIds: $userId) + @filter(predicate: "age>=18") + { + userId + age + firstName + lastName + } +} + +query parseFetchedValueToAnotherFieldArgumentMap($itemIds:[Int]){ + + itemList(itemIds: $itemIds){ + # save sellerId as List with unique name "sellerIdList" + sellerId @fetchSource(name: "sellerIdList") + name + saleAmount + salePrice + } + + userInfoList(userIds: 1) + # transform the argument of "userInfoList" named "userIds" according to expression "sellerIdList" and expression argument, + # which mean replace userIds value by source named "sellerIdList" + @argumentTransform(argumentName: "userIds", + operateType: MAP, + expression: "sellerIdList", + dependencySources: ["sellerIdList"] + ){ + userId + name + age + } +} +``` + +See [graphql-calculator README](https://github.com/graphql-calculator/graphql-calculator) for more information. +