gpt4 book ai didi

node.js - 带有 Node 的 .gql 或 .graphql 文件类型

转载 作者:IT老高 更新时间:2023-10-28 23:20:38 26 4
gpt4 key购买 nike

我将 Apollo 的 graphql-server-express 与 Node 一起使用,我想将我的“typedef”模式定义文件转换为 .graphql 或 .gql 文件清晰度和语法突出显示。

最好的方法是什么?除了 Babel(?) 之外,我在网上找不到任何好的资源,这似乎是唯一的选择。

非常感谢您的帮助!

最佳答案

我确定您到目前为止找到了解决方案,但对其他人来说这可能会有所帮助 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 })

示例

导入特定字段

假设如下目录结构:

.
├── a.graphql
├── b.graphql
└── c.graphql

a.graphql

# import B from "b.graphql"

type A {
# test 1
first: String
second: Float
b: B
}

b.graphql

# import C from 'c.graphql'

type B {
c: C
hello: String!
}

c.graphql

type C {
id: ID!
}

关于node.js - 带有 Node 的 .gql 或 .graphql 文件类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43594675/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com