I'm trying to import some backend methods apps/backend/...
into my packages/graphql
because my graphql resolvers actualy calls backend routes, but I can't seem to see how in turbo monorepo documentation...
my current frontend (client
) imports "@repo/graphql" : "*"
but now i need my graphql package to access my backend (server
) methods, but I can't just workaround that with relative path, because turbo will not resolve it after deployment.
does anyone have an idea ?
would you recommand me to have graphql as an app in /apps
or the packages strategy is a good idea perhaps ?
here is somme information:
let's say I have a getComment
from my ./apps/server/src/domain/task/comment.controller.ts
and that I access that ressource through graphql ./packages/graphql/graphql/src/resolvers.ts
, the resolver would call that specific method.
.
├── apps
│ ├── client
│ └── server
├── packages
│ ├── graphql
│ │ ├── graphql
│ │ │ ├── schema.gql
│ │ │ ├── resolvers.ts
│ │ │ └── src
│ │ ├── package.json
│ │ ├── src
│ │ │ ├── schema.graphql
│ │ │ └── server.ts
│ │ ├── README.md
│ │ ├── codegen.yml
│ │ └── tsconfig.json
│ └── prisma
├── README.md
├── docker-compose.yml
├── eslint.config.mjs
├── makefile
├── package-lock.json
├── package.json
├── prettier.config.mjs
├── tsconfig.json
└── turbo.json
You neet to export your methods from ./apps/server Nestjs application like a package does in monorepo.
Here are the steps to do so.
src/export.ts
file in apps/server
and export * from whatever file or methods which has to be used by graphql package.// src/export.ts
export * from "./domain/task/comment.controller.ts"
src/export.ts
from apps/server/package.json
// ./apps/server/package.json
{
"name": "server",
"version": "0.0.1",
"description": "",
// like this
"exports": {
".": "./src/export.ts"
},
"dependencies":{
"@nestjs/common": "^10.0.0",
}
}
/packages/graphql
. In ./packages/graphql/package.json
add "server":"workspace:*"
to dependencies
object.// ./packages/graphql/package.json
{
"name": "your-graphql-package",
"version": "0.0.1",
"description": "",
"exports": {
"types": "./src/export.d.ts"
},
"dependencies":{
"server":"workspace:*"
// other dependencies
}
}
And finally run npm/pnpm/yarn/bun install
to let turborepo resolve dependencies for graphql
package from server
app.
You can now import your server packages into your graphql packages by doing something like.
// ./packages/graphql/index.ts
import { CommentController } from "server";
Although it is not recommendad to export from apps/ folder to packges/. You might want to reconsider the architechture of your application.