【发布时间】:2019-03-26 21:00:15
【问题描述】:
我从.graphql 文件中搜索了一些有关导入类型的信息。我发现graphql-import 可以使用# import something from 'something-else' 导入。这在.graphql 文件之间运行良好。
但我想做的是从 Prisma 的 generated.graphql 导入一些 types 到 .js 文件中。
例如:
我有这个来自 Prisma 的 generated.graphql 文件
"""generated.graphql file"""
type ItemWhereInput { ... }
type ItemConnection { ... }
...
我想将ItemWhereInput和ItemConnection这两种类型从generated.graphql文件导入items-types.js文件
// items-types.js file
import gql from 'graphql-tag';
// I would like to make some kind of import ItemWhereInput and ItemConnection here
// Something like `import { ItemWhereInput, ItemConnection } from 'generated.graphql'`
...
const ItemWhereUniqueInput = gql`
input ItemWhereUniqueInput {
id: String!
}
`;
...
// And export ItemWhereInput and ItemConnection here
export default [Item, ItemInput, ItemWhereUniqueInput, ItemUpdateInput];
这样我就可以从graphql-tools 调用makeExecutableSchema 并在其他地方使用这些类型
// items-query.js file
import { forwardTo } from 'prisma-binding';
const schema = `
items: [Item]!
item (where: ItemWhereUniqueInput!): Item
# And use it here
itemsConnection (where: ItemWhereInput): ItemConnection!
`;
const resolvers = {
items: forwardTo(‘db’),
item: forwardTo(‘db’),
itemsConnection: forwardTo(‘db’),
};
export default {
schema,
resolvers,
};
如果它在其他地方或者有什么可以帮助的,请指出我。
谢谢。
【问题讨论】:
标签: javascript types import graphql prisma