mercurius-js / mercurius

Implement GraphQL servers and gateways with Fastify
https://mercurius.dev/
MIT License
2.35k stars 237 forks source link

validationRule not working even when setting cache to false #533

Open benjaminIDruide opened 3 years ago

benjaminIDruide commented 3 years ago

Hi, I have installed mercurius 8.0.0 and when I try to make validatioRule options working, I no other choice to set cache to false. Doing this, server starts but for any request I am passing to the gateway , I get this king of error

{
  "data": {
    "accounts": null
  },
  "errors": [
    {
      "message": "Cannot read property 'get' of null",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "accounts"
      ]
    }
  ]
}

here is my configuration on the 2 apollo server services

gateway.register(mercurius, {
    graphiql: false,
    ide: false,
    path: '/graphql',
    jit: 1,
    gateway: {
      services: [{
        name: 'accounts',
        url: 'http://localhost:4002/graphql',
        rewriteHeaders: (headers, context) => {
          return { 'Authorization': headers.authorization }
        }
      }, {
        name: 'user',
        url: 'http://localhost:4003/graphql',
        rewriteHeaders: (headers, context) => {
          return { 'Authorization': headers.authorization }
        }
      }]
    },

   validationRules:() => []  

  ,cache: false

})

just removing the validationRules option , and setting back to cache:true makes the call successful

benjaminIDruide commented 3 years ago

did another test right now, just setting cache to false induce this error

mcollina commented 3 years ago

Could you add a script to fully reproduce the problem? Or at least enable the logs of fastify and include the full stacktrace?