Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to implement with Apollo server v3 #81

Open
@daniel-keller

Description

@daniel-keller

I spent several hours finding the best way to implementgraphql-query-complexity with Apollo server v3 (server and serverless)
and I just wanted to post the answer in case anyone else needs it.

The trouble I ran into is that apollo server doesn't give its validationRules access to the request object so calculating query complexity based on request parameters is not possible. In apollo validationRules arenot guaranteed to run on every request.

The solution is to use the plugin api's didResolveOperation hook to manually trigger a complexity calculation further along the request pipeline asexplained here.

If you are using express (apollo-server-express or apollo-server-lambda or apollo-server-cloud-functions) you could probably do this as express middleware as well.

Feel free to close this Issue.

EDIT: You will need to modify the code example to work with the latest version ofgraphql-query-complexity (fieldConfigEstimator is deprecated). If you are using Apollo and building your schema usinggql() you may also need to convert your schema into a GraphQLSchema. Graphql includes a utility to do thisimport { buildASTSchema } from 'graphql';.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp