Escape-Technologies / graphql-armor

🛡️ The missing GraphQL security security layer for Apollo GraphQL and Yoga / Envelop servers 🛡️
https://escape.tech/graphql-armor/docs/getting-started
MIT License
500 stars 30 forks source link

protect().validationRules not assignable to ApolloServer.validationRules #513

Closed mmmattos closed 1 year ago

mmmattos commented 1 year ago

Hello, Reproducing here what happens in the ApolloServer constructor when including the validationRules property:

import { ApolloArmor } from '@escape.tech/graphql-armor';
import { ValidationRule } from 'graphql';

const armor = new ApolloArmor();

const protection = armor.protect();

const valRules : ValidationRule[] = protection.validationRules;

In this code, valRules reports in the IDE:

Type 'import("/Users/mmmattos/code/node_modules/@escape.tech/graphql-armor-cost-limit/node_modules/graphql/validation/ValidationContext").ValidationRule[]' is not assignable to type 'import("/Users/mmmattos/code/node_modules/graphql/validation/ValidationContext").ValidationRule[]'.
  Type 'import("/Users/mmmattos/code/node_modules/@escape.tech/graphql-armor-cost-limit/node_modules/graphql/validation/ValidationContext").ValidationRule' is not assignable to type 'import("/Users/mmmattos/code/node_modules/graphql/validation/ValidationContext").ValidationRule'.
    Types of parameters 'context' and 'context' are incompatible.
      Type 'import("/Users/mmmattos/code/node_modules/graphql/validation/ValidationContext").ValidationContext' is not assignable to type 'import("/Users/mmmattos/code/node_modules/@escape.tech/graphql-armor-cost-limit/node_modules/graphql/validation/ValidationContext").ValidationContext'.
        Types have separate declarations of a private property '_schema'.ts(2322)

Thanks for any advice on how to solve this.

mmmattos commented 1 year ago

This solved to a mismatch in the graphl version between graphql-armor (using graphql 16.8.0) and the graphql package in the root of the project (graphql 16.0.0). Aligning them to 16.8.0, fixed the issue