I am utilizing the @graphql-codegen/cli
tool to automatically generate TypeScript types from my GraphQL server.
Below is the content of my 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"
Here is the script in my package.json
to generate the types (yarn schema
):
"schema": "graphql-codegen --config codegen.yml"
These configurations were set up automatically by running the CLI wizard with yarn codegen init
.
However, I encounter errors when I execute yarn schema
, and here are the details of the issues:
https://i.sstatic.net/5RvHt.png
(The server is up and running at http://localhost:3001/graphql
, exposing the GraphQL schema).
Thank you for any assistance and suggestions provided.
Here is the .graphql file hosted on my server (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!
}