Reputation:
I'm attempting to refactor my Node-based Apollo GraphQL server instance to use .graphqls schema files instead of being string-based. I'm attempting to go by the example here to include the files in my schema:
import facility_schema from './facility-objects.graphqls';
however, I get a SyntaxError from the import. This happens if I just run either node or babel-node. However, running this sample project on GitHub, it appears to work.
Am I missing a package? Am I using the wrong interpreter? I know I'm missing something, I just don't know what.
Upvotes: 3
Views: 2509
Reputation: 972
For plain Node/Apollo, the following worked for me (with babel-node
):
import { readFileSync } from 'fs'
const schema = readFileSync(__dirname + '/schema.graphqls', 'utf8')
For Meteor/Apollo, you can try using the following new plugin (didn't try it myself, though):
https://github.com/Swydo/meteor-graphql
Upvotes: 10