apollo-server
apollo-server copied to clipboard
ENOENT: no such file or directory, open './schema.graphql'
Issue Description
Going over docs I stuck on https://www.apollographql.com/docs/apollo-server/workflow/generate-types The documentation says: "move your server's schema into a .graphql file" and then use it like so:
// ...other imports
import { readFileSync } from 'fs';
// Note: this uses a path relative to the project's
// root directory, which is the current working directory
// if the server is executed using `npm run`.
const typeDefs = readFileSync('./schema.graphql', { encoding: 'utf-8' });
Error:
node:fs:592
handleErrorFromBinding(ctx);
^
Error: ENOENT: no such file or directory, open './schema.graphql'
at Object.openSync (node:fs:592:3)
at readFileSync (node:fs:460:35)
at file:///Users/<location>/index.js:6:18
at ModuleJob.run (node:internal/modules/esm/module_job:192:25) {
errno: -2,
syscall: 'open',
code: 'ENOENT',
path: './schema.graphql'
}
Link to Reproduction
https://github.com/egor-sorokin/graphql-try
Reproduction Steps
- install dependecies
- run
npm run start
The problem is that tsc puts its output files in the dist
directory, which is what ends up being the current directory at runtime. But it doesn't have a built-in way to copy other files to dist
. There are plenty of work-arounds here (eg see the comments on that issue) — I'm not sure which one would be best for the docs.