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/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. 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); }); ```