【发布时间】:2020-03-13 05:21:03
【问题描述】:
我正在使用 @graphql-codegen/cli 工具从我的 graphql 服务器生成打字稿类型。
这是我的codegen.yml 内容:
overwrite: true
schema: "http://localhost:3001/graphql"
documents: "src/**/*.graphql"
generates:
src/generated/graphql.tsx:
plugins:
- "typescript"
- "typescript-operations"
- "typescript-react-apollo"
./graphql.schema.json:
plugins:
- "introspection"
这是我用来生成类型的package.json 脚本 (yarn schema):
"schema": "graphql-codegen --config codegen.yml"
所有这些都是通过执行cli向导yarn codegen init自动生成的。
但是当我运行yarn schema 时,我得到了以下错误:
(服务器在http://localhost:3001/graphql 上运行并公开了图形模式。
感谢您的帮助和建议
这是托管在我的服务器中的 .graphql 文件 (http://localhost:3001/graphql
# -----------------------------------------------
# !!! THIS FILE WAS GENERATED BY TYPE-GRAPHQL !!!
# !!! DO NOT MODIFY THIS FILE BY YOURSELF !!!
# -----------------------------------------------
"""Date custom scalar type"""
scalar Date
type Mutation {
create_user(user: UserInput!): User!
create_pofficer(pofficer: POfficerCreateInput!): POfficer!
create_incident(incident: TIncidentInput!): TIncident!
add_incident_type(incident_type: TIncidentTypeInput!): TIncidentType!
}
type POfficer {
_id: ID!
userid: ID!
user: User!
}
input POfficerCreateInput {
name: String!
surname: String!
phone: String!
}
type Query {
users: [User!]!
pofficers: [POfficer!]!
incidents: [TIncident!]!
incident_types: [TIncidentType!]!
}
type TIncident {
_id: ID!
createdAt: Date!
incidenttype_id: ID!
pofficer_id: ID!
toffender_id: ID
toffender_phone: String!
carnumber: String!
incident_status: String!
pofficer: POfficer!
toffender: User!
incident_type: TIncidentType!
}
input TIncidentInput {
incidenttype_id: ID!
pofficer_id: ID!
toffender_phone: String!
carnumber: String!
}
type TIncidentType {
_id: ID!
name: String!
description: String
}
input TIncidentTypeInput {
name: String!
description: String
}
type User {
_id: ID!
name: String!
surname: String!
email: String
phone: String!
}
input UserInput {
name: String!
surname: String!
email: String!
phone: String!
}
【问题讨论】:
-
您是否创建了任何带有查询或突变的
.graphql文件?你能把它们贴在这里吗? -
@Felipe 我已经编辑了我的问题,并添加了由我的服务器在
http://localhost:3001/graphql托管和公开的.graphql文件
标签: typescript graphql codegen graphql-codegen