eddeee888 / graphql-code-generator-plugins

List of GraphQL Code Generator plugins that complements the official plugins.
MIT License
44 stars 10 forks source link

[BUG] TypeError: Cannot read properties of undefined (reading 'body') #231

Closed Dakuan closed 4 months ago

Dakuan commented 4 months ago

im getting the following error:

test-1      |     TypeError: Cannot read properties of undefined (reading 'body')
test-1      |
test-1      |       4 | import { type Context } from "./Context";
test-1      |       5 |
test-1      |     > 6 | export const server = new ApolloServer<Context>({
test-1      |         |                       ^
test-1      |       7 |   typeDefs,
test-1      |       8 |   resolvers,
test-1      |       9 | });
test-1      |
test-1      |       at getLocation (node_modules/graphql/language/location.js:23:30)
test-1      |       at node_modules/graphql/error/GraphQLError.js:128:39
test-1      |           at Array.map (<anonymous>)
test-1      |       at new GraphQLError (node_modules/graphql/error/GraphQLError.js:127:25)
test-1      |       at SchemaValidationContext.reportError (node_modules/graphql/type/validate.js:73:7)
test-1      |       at validateFields (node_modules/graphql/type/validate.js:301:17)
test-1      |       at validateTypes (node_modules/graphql/type/validate.js:244:7)
test-1      |       at validateSchema (node_modules/graphql/type/validate.js:43:3)
test-1      |       at assertValidSchema (node_modules/graphql/type/validate.js:56:18)
test-1      |       at Function.generateSchemaDerivedData (node_modules/@apollo/server/src/ApolloServer.ts:730:5)
test-1      |       at Object.schemaDerivedDataProvider (node_modules/@apollo/server/src/ApolloServer.ts:275:28)
test-1      |       at new SchemaManager (node_modules/@apollo/server/src/utils/schemaManager.ts:79:36)
test-1      |       at new ApolloServer (node_modules/@apollo/server/src/ApolloServer.ts:272:26)
test-1      |       at src/graphql/server.ts:6:23

graphql/user/schema.graphql

extend type Query {
  me: User
}

type User {
  id: Int
  name: String
}

type UserCreateInput {
  firstName: String!
  lastName: String!
}

extend type Mutation {
  userCreate(input: UserCreateInput!): User!
}

codegen.ts

import type { CodegenConfig } from "@graphql-codegen/cli";
import { defineConfig } from "@eddeee888/gcg-typescript-resolver-files";

const config: CodegenConfig = {
  schema: "**/schema.graphql",
  generates: {
    "src/graphql": defineConfig({
      typesPluginsConfig: {
        contextType: "./Context#Context",
        mappers: {
          User: ".prisma/client#User as UserModel",
        },
      },
    }),
  },
};

export default config;
Dakuan commented 4 months ago

this was due to a mistake the gql schema:

type UserCreateInput {
  firstName: String!
  lastName: String!
}

should have been

input UserCreateInput {
  firstName: String!
  lastName: String!
}

not the most obvious of errors!