ArmorConfig is not setting the default value in version 6.x

I have a project running on version 6.6.0 and I came across the following error “GraphQLError: Syntax Error: Query depth limit of 6 exceeded, found 7.”. When researching I saw that it was a new configuration to be made in graphQLHandler, however, when setting it to other values ​​(higher or lower) the error still remains. Has anyone gone through something similar?

System:
OS: Windows 11 10.0.22631
Binaries:
Node: 18.20.2
Yarn: 3.2.3
Browsers:
Edge: Chromium (123.0.2420.97)
npmPackages:
@redwoodjs/auth-dbauth-setup: 6.6.0 => 6.6.0
@redwoodjs/core: 6.6.0 => 6.6.0

1 Like

Hi @gabrielalvesc thanks for the question – let’s see if we can track this down.

Could you share the query that exceeds the limit?

Looking at the types:

export type MaxDepthOptions = {
    n?: number;
    ignoreIntrospection?: boolean;
    flattenFragments?: boolean;
} & GraphQLArmorCallbackConfiguration;

Note: enabled comes from

export type ProtectionConfiguration = {
    enabled?: boolean;
};

The only thing I can think of is to

export type ArmorConfig = {
  logContext?: boolean
  logErrors?: boolean
} & GraphQLArmorConfig

maybe enable some logging for more info?

A small reproducible project would help – I’ll try to make one and see if I can see the same error.

@gabrielalvesc

I quickly set a really low maxDepth of 1 in an existing project:


export const handler = createGraphQLHandler({
  authDecoder,
  getCurrentUser,
  loggerConfig: { logger, options: {} },
  directives,
  sdls,
  services,
  armorConfig: {
    maxDepth: {
      n: 1,
    },
  },
  onException: () => {
    // Disconnect from your database with an unhandled exception.
    db.$disconnect()
  },
})

And I get:

api | GraphQLError: Syntax Error: Query depth limit of 1 exceeded, found 3.
api |     at MaxDepthVisitor.onOperationDefinitionEnter (/Users/dthyresson/tmp/rw-supabase-mw/node_modules/@escape.tech/graphql-armor-max-depth/dist/graphql-armor-max-depth.cjs.dev.js:64:19)

And my query was:

    query BlogPostsQuery {
      blogPosts: posts {
        id
        title
        body
        author {
          email
          fullName
        }
        createdAt
      }
    }

if I set depth to 3, the query executes and returns. If I set to 2, I get an error.

I also looked at the tests I wrote some time ago for Escape Tech – graphql-armor/examples/yoga/test/index.spec.ts at main · Escape-Technologies/graphql-armor · GitHub

And the Yoga example does respect the maxDepth n.

Can you share a repo that I can use the reproduce?

Could you confirm your version of GraphQL Armor?

yarn why @escape.tech/graphql-armor           
   └─ @escape.tech/graphql-armor@npm:2.3.1 [072bf] (via npm:2.3.1 [072bf])

I am running 2.3.1.

We’ll eventually update to 2.4.0.

Hey @dthyresson, thanks for answering me!

So, in the meantime, I ended up generating another project in version 6.6.0 and realized where the error was. In the project that I had, we were configuring the GraphQLHandler in the api/src/server.ts file. I noticed that I was not passing the maxDepth property correctly. So, when configured properly, it worked.

Anyway, thank you very much for your response!

No problem @gabrielalvesc and glad it’s working.

I had though of asking if you used server :slight_smile:

Hopefully renovate will update to the latest version of armor in an upcoming release.