简体   繁体   English

如何在Node应用程序中使用.graphqls文件?

[英]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. 我正在尝试重构我的基于节点的Apollo GraphQL服务器实例以使用.graphqls模式文件而不是基于字符串。 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. 但是,我从导入中得到一个SyntaxError This happens if I just run either node or babel-node . 如果我只运行节点babel节点,就会发生这种情况。 However, running this sample project on GitHub, it appears to work. 但是,在GitHub上运行此示例项目,它似乎工作。

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 ): 对于普通节点/阿波罗,以下适用于我(使用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): 对于Meteor / Apollo,您可以尝试使用以下新插件(尽管我自己也没试过):

https://github.com/Swydo/meteor-graphql https://github.com/Swydo/meteor-graphql

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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