From 81922f9697ce3f08afbfda3e8dfc2f78e1c0b129 Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Tue, 5 Mar 2024 13:17:20 +0530 Subject: [PATCH 1/2] update format --- docs/operators/const.md | 90 +++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/docs/operators/const.md b/docs/operators/const.md index c453e8cca3..a33d203b15 100644 --- a/docs/operators/const.md +++ b/docs/operators/const.md @@ -4,48 +4,52 @@ title: "@const" The `@const` directive in GraphQL is a powerful tool for embedding data directly into your schema, offering two primary functionalities: -1. **Static Response**: This feature allows for the inclusion of a constant response within the schema definition itself. It is useful for scenarios where the response is static and unchanging. e.g: - - ```graphql - schema { - query: Query - } - - type Query { - user: User @const(data: {name: "John", age: 12}) - } - - type User { - name: String - age: Int - } - ``` - - The const operator also checks the provided value at compile time to ensure it matches the field's schema. If not, the console displays a descriptive error message. - -2. **Dynamic Template**: Beyond static data embedding, the `@const` directive extends its utility to support dynamic data injection through Mustache template syntax. This feature enables the use of placeholders within the constant data, which are then dynamically replaced with actual values at runtime. It supports both scalar values and complex objects, including lists and nested objects, offering flexibility in tailoring responses to specific needs. e.g: - - ```graphql - schema { - query: Query - } - - type Query { - user: User @const(data: {name: "John", workEmail: "john@xyz.com", personalEmail: "john@xyz.com"}) - } - - type User { - name: String - age: Int - personalEmail: String - workEmail: String - emails: Emails @const(data: {emails: {workEmail: "{{value.workEmail}}", personalEmail: "{{value.personalEmail}}"}}) - } - - type Emails { - workEmail: String - personalEmail: String - } - ``` +## Static + +This feature allows for the inclusion of a constant response within the schema definition itself. It is useful for scenarios where the response is unchanging. e.g: + +```graphql +schema { + query: Query +} + +type Query { + user: User @const(data: {name: "John", age: 12}) +} + +type User { + name: String + age: Int +} +``` + +The const operator also checks the provided value at compile time to ensure it matches the field's schema. If not, the console displays a descriptive error message. + +## Dynamic + +Beyond static data embedding, the `@const` directive extends its utility to support dynamic data injection through Mustache template syntax. This feature enables the use of placeholders within the constant data, which are then dynamically replaced with actual values at runtime. It supports both scalar values and complex objects, including lists and nested objects, offering flexibility in tailoring responses to specific needs. e.g: + +```graphql +schema { + query: Query +} + +type Query { + user: User @const(data: {name: "John", workEmail: "john@xyz.com", personalEmail: "john@xyz.com"}) +} + +type User { + name: String + age: Int + personalEmail: String + workEmail: String + emails: Emails @const(data: {emails: {workEmail: "{{value.workEmail}}", personalEmail: "{{value.personalEmail}}"}}) +} + +type Emails { + workEmail: String + personalEmail: String +} +``` In this example, the `@const` directive dynamically generate an `Emails` object based on the provided template data. The placeholders within the template (`{{value.workEmail}}` and `{{value.personalEmail}}`) gets replaced with the actual values specified in the `User` type, allowing for dynamic content generation while still adhering to the schema's structure. From 8221a0fc292727be6dd90b246a0bac4350b1bece Mon Sep 17 00:00:00 2001 From: Tushar Mathur Date: Tue, 5 Mar 2024 20:44:40 +0530 Subject: [PATCH 2/2] update docs --- docs/operators/graphql.md | 2 -- docs/operators/grpc.md | 14 +++++--------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/docs/operators/graphql.md b/docs/operators/graphql.md index 132746451b..cd962270b1 100644 --- a/docs/operators/graphql.md +++ b/docs/operators/graphql.md @@ -2,8 +2,6 @@ title: "@graphQL" --- -## @graphQL - The **@graphQL** operator allows to specify GraphQL API server request to fetch data from. ```graphql showLineNumbers diff --git a/docs/operators/grpc.md b/docs/operators/grpc.md index 524aa564a8..1c44a54617 100644 --- a/docs/operators/grpc.md +++ b/docs/operators/grpc.md @@ -16,8 +16,6 @@ type Query { This schema snippet demonstrates the directive's application, where a query for `users` triggers a gRPC request to the `UserService`'s `ListUsers` method, thereby fetching the user data. -## Understanding the Proto File Structure - The `.proto` file delineates the structure and methods of the gRPC service. A simplified example of such a file is as follows: ```proto @@ -61,9 +59,7 @@ schema @link(src: "./users.proto", type: Protobuf) { Tailcall automatically resolves the protobuf file for any methods referenced in the `@grpc` directive. -### Directive Parameters - -#### `method` +## method This parameter specifies the gRPC service and method to be invoked, formatted as `..`: @@ -73,7 +69,7 @@ type Query { } ``` -#### `baseURL` +## baseURL Defines the base URL for the gRPC API. If not specified, the URL set in the `@upstream` directive is used by default: @@ -83,7 +79,7 @@ type Query { } ``` -#### `body` +## body This parameter outlines the arguments for the gRPC call, allowing for both static and dynamic inputs: @@ -97,7 +93,7 @@ type Query { } ``` -#### `headers` +## headers Custom headers for the gRPC request can be defined, facilitating the transmission of authentication tokens or other contextual data: @@ -108,7 +104,7 @@ type Query { } ``` -#### `groupBy` +## groupBy This argument is employed to optimize batch requests by grouping them based on specified response keys, enhancing performance in scenarios requiring multiple, similar requests: