0

My schema is defined:

export default gql`
  enum MyCoolEnum {
    A
    B
    C
  }

  extend type Mutation {
    changeValue(
      valueToChange: MyCoolEnum!
    ): JSON
  }
`;

Which produces the following in the generatedSchema

export enum MyCoolEnum {
  A = 'A',
  B = 'B',
  C = 'C'
}

And my codegen.yml looks like

schema: schema.graphql
generates:
  ./src/types/__generated__/graphqlSchema.ts:
    plugins:
      - typescript
      - typescript-resolvers

In my resolver this works

import { Resolvers, MyCoolEnum } from 'types/__generated__/graphqlSchema';

const resolvers: Resolvers = {
  Mutation: {
    changeValue: async (_, { valueToChange }) => {
      if (valueToChange === 'A') {
        // change A value
      } else if (valueToChange === 'B') {
        // change B value
      } else {
        // change C value
      }
    },
  },
};

But the second I reference the generated enum, like the following, I get Error: Cannot find module 'types/__generated__/graphqlSchema'

import { Resolvers, MyCoolEnum } from 'types/__generated__/graphqlSchema';

const resolvers: Resolvers = {
  Mutation: {
    changeValue: async (_, { valueToChange }) => {
      if (valueToChange === MyCoolEnum.A) {
Afs35mm
  • 549
  • 2
  • 8
  • 21

0 Answers0