pub trait Extension: Sync + Send + 'static {
    fn request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ExtensionContext<'life2>,
        next: NextRequest<'life3>
    ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait
, { ... } fn subscribe<'s>(
        &self,
        ctx: &ExtensionContext<'_>,
        stream: BoxStream<'s, Response>,
        next: NextSubscribe<'_>
    ) -> BoxStream<'s, Response> { ... } fn prepare_request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ExtensionContext<'life2>,
        request: Request,
        next: NextPrepareRequest<'life3>
    ) -> Pin<Box<dyn Future<Output = ServerResult<Request>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait
, { ... } fn parse_query<'life0, 'life1, 'life2, 'life3, 'life4, 'life5, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ExtensionContext<'life2>,
        query: &'life3 str,
        variables: &'life4 Variables,
        next: NextParseQuery<'life5>
    ) -> Pin<Box<dyn Future<Output = ServerResult<ExecutableDocument>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        'life4: 'async_trait,
        'life5: 'async_trait
, { ... } fn validation<'life0, 'life1, 'life2, 'life3, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ExtensionContext<'life2>,
        next: NextValidation<'life3>
    ) -> Pin<Box<dyn Future<Output = Result<ValidationResult, Vec<ServerError>>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait
, { ... } fn execute<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ExtensionContext<'life2>,
        operation_name: Option<&'life3 str>,
        next: NextExecute<'life4>
    ) -> Pin<Box<dyn Future<Output = Response> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        'life4: 'async_trait
, { ... } fn resolve<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>(
        &'life0 self,
        ctx: &'life1 ExtensionContext<'life2>,
        info: ResolveInfo<'life3>,
        next: NextResolve<'life4>
    ) -> Pin<Box<dyn Future<Output = ServerResult<Option<Value>>> + Send + 'async_trait>>
    where
        Self: 'async_trait,
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        'life3: 'async_trait,
        'life4: 'async_trait
, { ... } }
Expand description

Represents a GraphQL extension

Provided Methods§

Called at start query/mutation request.

Examples found in repository?
src/extensions/mod.rs (lines 156-162)
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
    pub async fn run(self, ctx: &ExtensionContext<'_>) -> Response {
        if let Some((first, next)) = self.chain.split_first() {
            first
                .request(
                    ctx,
                    NextRequest {
                        chain: next,
                        request_fut: self.request_fut,
                    },
                )
                .await
        } else {
            self.request_fut.await
        }
    }

Called at subscribe request.

Examples found in repository?
src/extensions/mod.rs (line 183)
177
178
179
180
181
182
183
184
185
186
187
    pub fn run<'s>(
        self,
        ctx: &ExtensionContext<'_>,
        stream: BoxStream<'s, Response>,
    ) -> BoxStream<'s, Response> {
        if let Some((first, next)) = self.chain.split_first() {
            first.subscribe(ctx, stream, NextSubscribe { chain: next })
        } else {
            stream
        }
    }

Called at prepare request.

Examples found in repository?
src/extensions/mod.rs (line 200)
197
198
199
200
201
202
203
204
205
    pub async fn run(self, ctx: &ExtensionContext<'_>, request: Request) -> ServerResult<Request> {
        if let Some((first, next)) = self.chain.split_first() {
            first
                .prepare_request(ctx, request, NextPrepareRequest { chain: next })
                .await
        } else {
            Ok(request)
        }
    }

Called at parse query.

Examples found in repository?
src/extensions/mod.rs (lines 224-232)
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
    pub async fn run(
        self,
        ctx: &ExtensionContext<'_>,
        query: &str,
        variables: &Variables,
    ) -> ServerResult<ExecutableDocument> {
        if let Some((first, next)) = self.chain.split_first() {
            first
                .parse_query(
                    ctx,
                    query,
                    variables,
                    NextParseQuery {
                        chain: next,
                        parse_query_fut: self.parse_query_fut,
                    },
                )
                .await
        } else {
            self.parse_query_fut.await
        }
    }

Called at validation query.

Examples found in repository?
src/extensions/mod.rs (lines 254-260)
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
    pub async fn run(
        self,
        ctx: &ExtensionContext<'_>,
    ) -> Result<ValidationResult, Vec<ServerError>> {
        if let Some((first, next)) = self.chain.split_first() {
            first
                .validation(
                    ctx,
                    NextValidation {
                        chain: next,
                        validation_fut: self.validation_fut,
                    },
                )
                .await
        } else {
            self.validation_fut.await
        }
    }

Called at execute query.

Examples found in repository?
src/extensions/mod.rs (lines 279-286)
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
    pub async fn run(self, ctx: &ExtensionContext<'_>, operation_name: Option<&str>) -> Response {
        if let Some((first, next)) = self.chain.split_first() {
            first
                .execute(
                    ctx,
                    operation_name,
                    NextExecute {
                        chain: next,
                        execute_fut: self.execute_fut,
                    },
                )
                .await
        } else {
            self.execute_fut.await
        }
    }

Called at resolve field.

Examples found in repository?
src/extensions/mod.rs (lines 309-316)
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
    pub async fn run(
        self,
        ctx: &ExtensionContext<'_>,
        info: ResolveInfo<'_>,
    ) -> ServerResult<Option<Value>> {
        if let Some((first, next)) = self.chain.split_first() {
            first
                .resolve(
                    ctx,
                    info,
                    NextResolve {
                        chain: next,
                        resolve_fut: self.resolve_fut,
                    },
                )
                .await
        } else {
            self.resolve_fut.await
        }
    }

Implementors§