Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOENT: no such file or directory, open './schema.graphql' #7767

Open
egor-sorokin opened this issue Oct 24, 2023 · 1 comment
Open

ENOENT: no such file or directory, open './schema.graphql' #7767

egor-sorokin opened this issue Oct 24, 2023 · 1 comment
Labels
📝 documentation Focuses on changes to the documentation (docs)

Comments

@egor-sorokin
Copy link

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
@glasser
Copy link
Member

glasser commented Oct 24, 2023

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.

@glasser glasser added the 📝 documentation Focuses on changes to the documentation (docs) label Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📝 documentation Focuses on changes to the documentation (docs)
Projects
None yet
Development

No branches or pull requests

2 participants