You can configure certain RPC aspects within your next.config.js
file
inside the blitz property.
To change how every file path is resolved, you can set the resolverPath
option inside next.config.js
.
module.exports = withBlitz({
blitz: {
resolverPath: "queries|mutations",
},
})
// Or with a custom function
module.exports = withBlitz({
blitz: {
resolverPath: (filePath) => {
return filePath.replace("app/", "") // Removes `app/` from the path
},
},
})
There are three options to determine how the RPC path is resolved during build.
queries|mutations
(default)queries
or mutations
folder as the rootroot
Example output:
File: src/products/queries/getProduct.ts
"queries|mutations" URL: /api/rpc/getProduct
"root" URL: src/products/queries/getProduct
File: src/products/mutations/createProduct.ts
"queries|mutations" URL: /api/rpc/createProduct
"root" URL: src/products/mutations/createProduct
File: src/products/mutations/v2/createProduct.ts
"queries|mutations" URL: /api/rpc/v2/createProduct
"root" URL: src/products/mutations/v2/createProduct
Inside the blitz
property add the param includeRPCFolders
as an array
of relative path folders from your Blitz root folder. For example:
module.exports = withBlitz({
blitz: {
includeRPCFolders: ["../../<YOUR DIRECTORY PATH>"],
},
})
Your resolvers still need to be placed in queries
or mutations
folders.
In your [[...blitz]].ts
api file you can see the following settings in the rpcHandler
logging?: {
/**
* allowList Represents the list of routes for which logging should be enabled
* If whiteList is defined then only those routes will be logged
*/
allowList?: string[]
/**
* blockList Represents the list of routes for which logging should be disabled
* If blockList is defined then all routes except those will be logged
*/
blockList?: string[]
/**
* verbose Represents the flag to enable/disable logging
* If verbose is true then Blitz RPC will log the input and output of each resolver
*/
verbose?: boolean
/**
* disablelevel Represents the flag to enable/disable logging for a particular level
*/
disablelevel?: "debug" | "info"
}
Blitz RPC defaults to:
verbose
to be true if it not configured.input
and resolver completion time
will be logged with the info
level.result
and next.js serialization time
will be logged with the debug
level.Example:
export default api(
rpcHandler({
onError: console.log,
formatError: (error) => {
error.message = `FormatError handler: ${error.message}`
return error
},
logging: {
verbose: true,
blockList: ["getCurrentUser", ...], //just write the resolver name [which is the resolver file name]
},
})
)
This is will enable verbose Blitz RPC logging for all resolvers except the resolvers getCurrentUser
and others mentioned in the blockList