Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for @defer directive in GraphQL #3206

Open
1 task done
yun8boo opened this issue May 1, 2024 · 2 comments
Open
1 task done

Support for @defer directive in GraphQL #3206

yun8boo opened this issue May 1, 2024 · 2 comments
Labels

Comments

@yun8boo
Copy link

yun8boo commented May 1, 2024

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

I would like to propose the addition of support for the @defer directive in GraphQL within the Nest.js framework.

The absence of support for the @defer directive in Nest.js presents a limitation for developers who are building GraphQL APIs with real-time or large datasets. Currently, Nest.js users are unable to take advantage of the @defer directive, which allows GraphQL servers to send parts of the response as soon as they are available, rather than waiting for the entire query to be resolved. This can result in suboptimal performance and increased latency for applications dealing with complex queries or real-time data updates.

Integrating support for the @defer directive into Nest.js would address this limitation and provide developers with a more efficient way to handle large and complex queries in GraphQL APIs. This enhancement would not only improve the performance and scalability of Nest.js applications but also contribute to a better overall developer experience.

Describe the solution you'd like

I propose adding native support for the @defer directive in the Nest.js GraphQL module. This would involve implementing the necessary functionality to recognize and process @defer directives within GraphQL queries handled by Nest.js servers.

Additionally, it would be beneficial to provide configuration options for fine-tuning the behavior of @defer, such as setting timeouts for deferred fields or specifying the maximum number of concurrent deferred responses.

By integrating support for@defer directly into the Nest.js framework, developers would have a seamless and efficient way to leverage this feature in their GraphQL APIs without relying on external libraries or custom implementations.

What is the motivation / use case for changing the behavior?

Teachability, documentation, adoption, migration strategy

No response

What is the motivation / use case for changing the behavior?

The motivation behind adding support for the @defer directive in Nest.js is to enhance the performance and scalability of GraphQL APIs built with the framework.

Use cases for this feature include:

Handling large and complex queries more efficiently by sending partial responses as soon as data becomes available, reducing overall latency for clients.
Supporting real-time data updates by deferring non-critical parts of the query, allowing critical data to be delivered to clients more quickly.
Improving the user experience for applications that rely on GraphQL APIs, especially those with interactive or real-time features, by minimizing wait times for query responses.
Overall, adding support for @defer in Nest.js would align the framework with modern best practices for building high-performance GraphQL APIs and provide developers with a powerful tool for optimizing query execution.

@yun8boo yun8boo added the feature label May 1, 2024
@leartbeqiraj1
Copy link

any update on this?

@hotsezus
Copy link

hotsezus commented Jun 19, 2024

Disclaimer: Beware that using those directives is still an experimental feature as Apollo Server still does not support the latest spec of this directives. There is a v17.0.0-alpha.3 release of graphql-js which is not supported by Apollo Server as it contains breaking changes in @defer and @stream directives execution


As long as i know, there is no need to do something on NestJS side.
Apollo Server already supports defer directive out of the box, the only issue on NestJS side is lack of documentation.
To make @defer and @stream directives work with ApolloDriver, you need to:

  1. Import GraphQLDeferDirective and GraphQLStreamDirective and apply them in GraphQL module config
import { GraphQLDeferDirective, GraphQLStreamDirective } from 'graphql';

GraphQLModule.forRoot({
  driver: ApolloDriver,
  buildSchemaOptions: {
    directives: [GraphQLDeferDirective, GraphQLStreamDirective],
  },
})
  1. Install apropriate versions of @apollo/server and graphql-js packages as said in Apollo Server docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants