How to import .graphql file to apollo server?

I have a .graphql file and I got many error trying to importing, I already search for the web but nothing solved my problem. In apollo docs only appears with React and Webpack, But I’m not using Webpack and least React.

Hi! You could read the .graphql file into your server as a string by doing something like this:

const { gql } = require("apollo-server");
const fs = require("fs");
const path = require("path");

const typeDefs = gql`
  ${fs.readFileSync(path.resolve(__dirname, "schema.graphql").toString())}
`;

I’ve always done it that way personally :woman_shrugging: I have a little demo app here where I do it that way.

Thanks, I never know that I need to convert into string first. And I’m using ES Module, so for is me:

import fs from 'fs'
import path from 'path'

const __dirname = path.resolve(path.dirname(''));

Dificult when most of the examples are in Common JS.