1

I try to import graphql schema with the following code:

import { importSchema } from 'graphql-import'

const typeDefs = importSchema(`./typeDefs/schema.graphql`)

I got an error:

fs.js:114
    throw err;
    ^

Error: ENOENT: no such file or directory, open './schema.graphql'
    at Object.openSync (fs.js:443:3)
    at Object.readFileSync (fs.js:343:35)
    at read (C:\Data\Dev\Yunazon\191121-serv\node_modules\graphql-import\src\index.ts:31:15)
    at importSchema (C:\Data\Dev\Yunazon\191121-serv\node_modules\graphql-import\src\index.ts:87:15)
    at Object.<anonymous> (C:\Data\Dev\Yunazon\191121-serv\src\graphQL/apolloServer.js:10:18)

What is an issue?

Roman
  • 19,236
  • 15
  • 93
  • 97

1 Answers1

2

After some research and thanks to the finding of @enBonnet (github community) I found the solution to change path parameter. For some reasons GraphQL tools require absolute path instead of relative one:

import { importSchema } from 'graphql-import'

const typeDefs = importSchema(`${__dirname}/typeDefs/schema.graphql`)
Roman
  • 19,236
  • 15
  • 93
  • 97