From 081a8d9e83db8439b7d45c74eb90da39991df1d6 Mon Sep 17 00:00:00 2001 From: dugenkui Date: Sun, 20 Mar 2022 23:23:44 +0800 Subject: [PATCH 1/2] add graphql-calculator (#118) --- .../server/graphql-calculator.md | 57 +++++++++++++++++++ 1 file changed, 57 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..536d42e8b8 --- /dev/null +++ b/src/content/code/language-support/java-kotlin-android/server/graphql-calculator.md @@ -0,0 +1,57 @@ +--- +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. From 34cfd948c2a47b99ed7ddc77299ac10a67ec3b79 Mon Sep 17 00:00:00 2001 From: yang <30883395+webvs2@users.noreply.github.com> Date: Fri, 16 Jun 2023 14:50:33 +0800 Subject: [PATCH 2/2] [docm] Fix instance code (#119) * [docm] Fix instance code * optimized code --- src/content/code/code.md | 2 +- src/content/graphql-js/Tutorial-GettingStarted.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/code/code.md b/src/content/code/code.md index 047225a853..623d31b891 100644 --- a/src/content/code/code.md +++ b/src/content/code/code.md @@ -304,7 +304,7 @@ var schema = buildSchema(` var root = { hello: () => 'Hello world!' }; -graphql(schema, '{ hello }', root).then((response) => { +graphql({schema, source:'{ hello }', rootValue:root}).then((response) => { console.log(response); }); ``` diff --git a/src/content/graphql-js/Tutorial-GettingStarted.md b/src/content/graphql-js/Tutorial-GettingStarted.md index cbd2a4319e..014f5440c8 100644 --- a/src/content/graphql-js/Tutorial-GettingStarted.md +++ b/src/content/graphql-js/Tutorial-GettingStarted.md @@ -40,7 +40,7 @@ var root = { }; // 运行 GraphQL query '{ hello }' ,输出响应 -graphql(schema, '{ hello }', root).then((response) => { +graphql({schema, source:'{ hello }', rootValue:root}).then((response) => { console.log(response); }); ```