From fa861a31d7c90226c608b88559eb1ac35966b229 Mon Sep 17 00:00:00 2001 From: Bhavya Jain Date: Sat, 2 Mar 2024 16:49:38 +0530 Subject: [PATCH] Updated documentation for link --- docs/operators/index.md | 1 + docs/operators/link.md | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 docs/operators/link.md diff --git a/docs/operators/index.md b/docs/operators/index.md index 7d4d406e1c..5e1432de58 100644 --- a/docs/operators/index.md +++ b/docs/operators/index.md @@ -18,6 +18,7 @@ Certainly! Here's the table with hyperlinks added back to the operator names: | [@graphQL](graphql.md) | Resolves a field or node by a GraphQL API. | | [@grpc](grpc.md) | Resolves a field or node by a gRPC API. | | [@http](http.md) | Resolves a field or node by a REST API. | +| [@link](link.md) | Incorporates external elements like configs, certificates, Protocol Buffers, etc., into the schema. | | [@modify](modify.md) | Enables changes to attributes of fields or nodes in the schema. | | [@omit](omit.md) | Excludes fields or nodes from the generated schema, making them inaccessible through the GraphQL API. | | [@server](server.md) | Provides server configurations for behavior tuning and tailcall optimization in specific use-cases. | diff --git a/docs/operators/link.md b/docs/operators/link.md new file mode 100644 index 0000000000..6d31ef9c9c --- /dev/null +++ b/docs/operators/link.md @@ -0,0 +1,66 @@ +--- +title: "@link Directive Documentation" +--- + +# @link Directive + +The **@link** directive is a crucial component for integrating external resources into your GraphQL schema. This documentation provides a detailed explanation of the directive's functionality, syntax, and the types it supports. + +## Overview + +The `@link` directive simplifies the process of incorporating external resources, including configurations, .proto files for gRPC services, and other files, into your GraphQL schema. This powerful operator allows for effective merging or utilization of external resources within the importing configuration. + +## How it Works + +The `@link` directive requires the specification of three key parameters: + +- **src**: This defines the source of the link, which can be a URL or a file path. When using a file path, it's relative to the location of the file importing the link. + +- **type**: Specifies the link's type, dictating how the imported resource integrates into the schema. Refer to the [Supported Types](#supported-types) section for a comprehensive list. + +- **id (Optional)**: An optional field allowing the assignment of a unique identifier to the link. This identifier proves beneficial for referencing the link within the schema. + +## Example + +Explore the following example showcasing the implementation of the `@link` directive. In this scenario, a Protocol Buffers (.proto) file for a gRPC service is seamlessly incorporated into the GraphQL schema: + +```graphql showLineNumbers +schema + @server(port: 9000, graphiql: true) + @upstream(baseURL: "http://localhost:60051", httpCache: true, batch: {delay: 5}) + @link(id: "blog", src: "../src/grpc/blog.proto", type: Protobuf) { + query: Query +} + +type Query { + blogPosts: BlogData! @grpc(method: "blog.BlogService.GetAllPosts") +} + +type BlogPost { + postId: Int + title: String + content: String + imageUrl: String +} + +type BlogData { + blogPosts: [BlogPost]! +} + +- The GraphQL schema defines a new BlogPost type with different fields such as postId, title, content, and imageUrl. +- The @link directive is used with a unique identifier (id: "blog") to incorporate a Protocol Buffers (.proto) file for a gRPC service related to blogs. +- The @upstream directive specifies a different port and base URL for the gRPC service. +- The @grpc directive within the Query type is used to fetch blog posts from the gRPC service. + +## Supported Types + +The `@link` directive offers support for various types, each fulfilling a specific role in the integration of external resources into your GraphQL schema: + +- **Config**: Imports a configuration file. +- **Protobuf**: Integrates a .proto file for gRPC services. +- **Script**: Permits the import of a JavaScript file. +- **Cert**: Includes a certificate file. +- **Key**: Facilitates the import of a key file. + +This level of flexibility empowers developers to seamlessly incorporate a wide range of external resources, enhancing the versatility of their GraphQL schema. +```