Resolvers with null context

Good afternoon everyone.
I’m trying to develop an app that exports a GraphQL call and a REST API.
The API is working fine, but when I try to use GraphQL it shows an error: “message”: “Cannot read properties of null (reading ‘clients’)”. It seems like the context is empty, but the code is identical to the REST API.

If anyone can help.




image (9)

Good morning dgpgean, how are you?
I recommend using the Node.js debugger (which you can connect to via Chrome DevTools through the “tunnel” that vtex link makes available) to analyze, at runtime, where the clients object is coming from. Based on what can be read in the error, it’s null, so you might not be reading the context correctly.
The problem might be in how you’re reading the parameters passed to your resolver function. Here in the GraphQL app example that VTEX provides:

all Resolvers receive an unused first parameter, defined as _ (underscore). In your searchCep resolver, you’re supposedly receiving ctx (context) as the second parameter instead of the third, as shown in the examples.

As I said, that might be the issue — I can’t say for sure, but it’s what caught my eye as soon as I saw the screenshot.

Hope that helps!