T
tRPC

Meta - unable to create default meta

Meta - unable to create default meta

MMugetsu3/20/2023
Trying to follow https://trpc.io/docs/server/metadata#default-meta-chaining-and-shallow-merging I set the type of the meta add it to the builder and want to set default but seems there is no typing for the meta in the create to set the default. Am I missing something ?
"@trpc/client": "10.16.0",
"@trpc/react-query": "10.16.0",
"@trpc/server": "10.16.0",
"@trpc/client": "10.16.0",
"@trpc/react-query": "10.16.0",
"@trpc/server": "10.16.0",
type CreateContextOptions = {
req: express.Request
res: express.Response
currentSchema: any
}

type MetaOptions = {
roles: string[]
}

export const createInnerTRPCContext = async (opts: CreateContextOptions) => ({
req: opts.req,
res: opts.res,
currentSchema: opts.currentSchema,
})

export const createTRPCContext = async (
opts: trpcExpress.CreateExpressContextOptions,
) => {
const { req, res } = opts
const currentSchema =
req.locationSchemas?.find(({ id }) => id === req.schemaId) || {}

return createInnerTRPCContext({
req,
res,
currentSchema,
})
}

const t = initTRPC
.context<typeof createTRPCContext>()
.meta<MetaOptions>()
.create({
/// defaultMeta <------------------------- MISSING TYPING
transformer: superjson,
errorFormatter({ shape, ctx }) {
const { data, ...rest } = shape

return {
...rest,
data: {
...data,
traceId: ctx?.req?.traceId,
schemaId: ctx?.req?.schemaId,
},
}
},
})
type CreateContextOptions = {
req: express.Request
res: express.Response
currentSchema: any
}

type MetaOptions = {
roles: string[]
}

export const createInnerTRPCContext = async (opts: CreateContextOptions) => ({
req: opts.req,
res: opts.res,
currentSchema: opts.currentSchema,
})

export const createTRPCContext = async (
opts: trpcExpress.CreateExpressContextOptions,
) => {
const { req, res } = opts
const currentSchema =
req.locationSchemas?.find(({ id }) => id === req.schemaId) || {}

return createInnerTRPCContext({
req,
res,
currentSchema,
})
}

const t = initTRPC
.context<typeof createTRPCContext>()
.meta<MetaOptions>()
.create({
/// defaultMeta <------------------------- MISSING TYPING
transformer: superjson,
errorFormatter({ shape, ctx }) {
const { data, ...rest } = shape

return {
...rest,
data: {
...data,
traceId: ctx?.req?.traceId,
schemaId: ctx?.req?.schemaId,
},
}
},
})
Nnlucas3/20/2023
Have you reloaded your language server since upgrading? the defaultMeta key should be there whether you set .meta<>() or not, so this is a weird one unless you just need to reload
MMugetsu3/20/2023
Yeah, I've restarted TS, Invalidated all cache and restarted IDE. Doesn't seem to pick it up I can't even find any definition in source code about defaultMeta
Nnlucas3/20/2023
In the source code in node modules, what’s the package.json version?
MMugetsu3/20/2023
MMugetsu3/20/2023
10.16.0 And yeah if I even define it it seems not working meta is undefined
{
type: 'query',
path: 'locations.searchLocations',
rawInput: {
search: '',
limit: 10,
offset: 0,
'filter:type': undefined,
'filter:storeFormat': undefined,
'filter:tradingStatus': undefined,
'filter:region': undefined
},
meta: undefined,
input: undefined
}
-----------------------END-----------------------
{
type: 'query',
path: 'locations.searchLocations',
rawInput: {
search: '',
limit: 10,
offset: 0,
'filter:type': undefined,
'filter:storeFormat': undefined,
'filter:tradingStatus': undefined,
'filter:region': undefined
},
meta: undefined,
input: undefined
}
-----------------------END-----------------------
Nnlucas3/20/2023
Oh you know what I don’t think we released that yet
MMugetsu3/20/2023
Aaaa I seee 😄
Nnlucas3/20/2023
Let me ping Alex
MMugetsu3/20/2023
sure no worries
Nnlucas3/20/2023
Thanks for flagging it, I think there was an internal issue after the release last week so probably this got forgotten Looks like 10.17 is out now 🙂
MMugetsu3/20/2023
Sweet. Will chceck in a moment Nice. Working as expected now. Thanks !

Looking for more? Join the community!

T
tRPC

Meta - unable to create default meta

Join Server
Recommended Posts
trpc/react-query batchingHi. How do you deal with batching? If I don't put any maxURLLength then I get an error 404 since it middleware error with minimal-react examplehello! I tried to use the minimal-react version, but I get an error - it says that `'middleware'` dohow to use the same Zod validation both client and server's procedure inputWhen submitting forms, I need the same validation. How to reduce the repeated code?pipe/unstable_pipeI cant seem to find it? according to the docs I can chain middlewares using pipe in v10 but the featImplementation of bi-directional cursor-based paginationI'm looking at the [example](https://trpc.io/docs/useInfiniteQuery#example-react-component) for `useHow to ignore `input` validation and just pass in an object with interfaces?For my input I just want to pass in an interface rather than using a Zod schema. Either that or if sWhere can I add a query key?I tried to follow as in useQuery from Tanstack, but Typescript started complaining ```js api.promptsasync inside link next handler possible ?Hey everyone, Today I had to do a bit of refactor, and I'm wondering something. I had to turn a syntRPC doesn't support redirectI use tRPC & @trpc/server/adapters/express. procdure.query({ctx: { res }} => { res.redirect('xxHow to get external key other than INPUT from RESTFUL request?SSO callback my api like api/trpc/user.login?token=abcCannot read properties of undefined (reading 'createTRPCReact')I'm trying to use it in an Astro project. https://github.com/Industrial/test-astro-solid/blob/main/application/octet-stream responseIm refactoring my old backend to trpc so far it was a pleasure and fairly straight forward process ❤Discriminated union handleHow Do I handle Input type if its discriminated union?? ``` export const batchTasksRouter = createHit external APIs ...I'm new to tRPC, I need to hit an external API (OpenAI) directly from the client-side. Can I still uCannot get subscription event to fireRipping my hair out here trying to get Websockets working with tRPC and Next. Everything seems to bHow to get response type depending on the input params?Simple example of a normal JS function with generics: ``` const example = <T extends unknown>(paramshow to build tRPC and Prisma with express?I am using TSC as the official docs example does. But when I use paths in tsconfig.json, It does notHow to infer types from input?When I call my procedure from the client I send an array of strings as an input. How can I infer theHow to infer types of a queryCoinsider the example `const hello = trpc.hello.useQuery();` I would like to export the type we get Data Visualisation/Chartsis anyone using tRPC on data visualisation (say bar chart/line chart) in a scenario close to a banki