简体   繁体   中英

How to use .graphqls files in a Node application?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM