Skip to content

Commit

Permalink
Merge branch 'develop' into doc/update-request
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored Mar 6, 2024
2 parents 8070d59 + 8221a0f commit 2d36f75
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 54 deletions.
90 changes: 47 additions & 43 deletions docs/operators/const.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", personalEmail: "[email protected]"})
}

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: "[email protected]", personalEmail: "[email protected]"})
}

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.
2 changes: 0 additions & 2 deletions docs/operators/graphql.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
title: "@graphQL"
---

## @graphQL

The **@graphQL** operator allows to specify GraphQL API server request to fetch data from.

```graphql showLineNumbers
Expand Down
14 changes: 5 additions & 9 deletions docs/operators/grpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 `<package>.<service>.<method>`:

Expand All @@ -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:

Expand All @@ -83,7 +79,7 @@ type Query {
}
```

#### `body`
## body

This parameter outlines the arguments for the gRPC call, allowing for both static and dynamic inputs:

Expand All @@ -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:

Expand All @@ -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:

Expand Down

0 comments on commit 2d36f75

Please sign in to comment.