Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
How to implement field-level complexity in graphql code-first approach?

I ran into such a problem when dealing with query complexity in GraphQL. The package I used is graphql-query-complexity.

App.js:

app.use(
  '/graphql',
  graphqlHTTP((req) => ({
    schema: schema,
    graphiql: true,
    validationRules: [
      createComplexityRule({
        estimators: [
          simpleEstimator({ defaultComplexity: 1 }),
        ],
        maximumComplexity: 20,
        },
      }),
    ]
  }))
);

It works well, but when I looked at other examples on the internet, I saw that they use Field-level complexity there. That is, they can set a different complexity for each field. But can't understand it because they use TypeGraphQL server, I use express-graphql

Example were:

@Field({ complexity: 3 })
title: string;

But my express-graphql code-first approach code:

const PostTypes: { comment: GraphQLObjectType } = {
  post: new GraphQLObjectType({
    name: 'Post',
    fields: () => ({
      title: { type: graphql.GraphQLString },
    }),
  }),
};

export default PostTypes;

So, how can I implement this for my structure?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!