rob*_*cat 10
我敢肯定,到目前为止,您已经找到了解决方案,但是对于其他人来说,这可能会有所帮助 https://github.com/prismagraphql/graphql-import。
import { importSchema } from 'graphql-import'
import { makeExecutableSchema } from 'graphql-tools'
const typeDefs = importSchema('schema.graphql')
const resolvers = {}
const schema = makeExecutableSchema({ typeDefs, resolvers })
Run Code Online (Sandbox Code Playgroud)
假定以下目录结构:
.
??? a.graphql
??? b.graphql
??? c.graphql
Run Code Online (Sandbox Code Playgroud)
图文
# import B from "b.graphql"
type A {
# test 1
first: String
second: Float
b: B
}
Run Code Online (Sandbox Code Playgroud)
b.graphql
# import C from 'c.graphql'
type B {
c: C
hello: String!
}
Run Code Online (Sandbox Code Playgroud)
图形库
type C {
id: ID!
}
Run Code Online (Sandbox Code Playgroud)
有同样的问题如何以正确的方式实施它。无论如何这对我有用。
import {gql} from 'apollo-server-express'
import * as types from './types.graphql'
export const typeDefs = gql`${types}`
Run Code Online (Sandbox Code Playgroud)
小智 6
schemas 文件夹应该包含带有 .graphql 或 .gql 文件的文件
const path = require('path');
const { loadFilesSync } = require('@graphql-tools/load-files');
const { mergeTypeDefs } = require('@graphql-tools/merge');
const typesArray = loadFilesSync(path.join(__dirname, './schemas'));
module.exports = mergeTypeDefs(typesArray, { all: true });
Run Code Online (Sandbox Code Playgroud)
Efo*_*osa -1
我有同样的问题,我相信在不将 babel/webpack 引入服务器端管道的情况下完成您所要求的唯一方法是将您的查询编写为导出的模板字符串。
例如
/* query.gql */
module.exports = `
schema {
query: Query
mutation: Mutation
}
type Query {
posts: [Post]
post(id:String, slug:String): Post
user(uid:String): User
}
...
`
Run Code Online (Sandbox Code Playgroud)
值得庆幸的是,GraphQL 的 VS Code 语法突出显示支持此方法。