graphql-nexus / nexus

Code-First, Type-Safe, GraphQL Schema Construction
https://nexusjs.org
MIT License
3.4k stars 275 forks source link

typeGenAutoConfig wrong relative path in Windows #41

Closed israelglar closed 5 years ago

israelglar commented 5 years ago

These lines generate the imports of the typegenAutoConfig. https://github.com/prisma/nexus/blob/18a306ee2903d98fc110c1067e1903ea0ee5f256/src/typegenAutoConfig.ts#L212-L215 And use this function https://github.com/prisma/nexus/blob/18a306ee2903d98fc110c1067e1903ea0ee5f256/src/typegenAutoConfig.ts#L340-L350

The problem is with this line:

    return `.${path.sep}${path.join(relative, filename)}`;

In Windows it generates an import statement with backslashes \, and when node tries to compile it, it can't.

Maybe change it to:

    return `./${path.join(relative, filename)}`;
tgriesser commented 5 years ago

Oops, I think I used path.sep specifically because I thought thats what was supposed to be used for Windows 😬

Let me know if it's fixed in 0.9.13

israelglar commented 5 years ago

That didn't fixed it :/ Maybe it's not that line, sorry. I'm trying to find where it is but with no luck.

That file and import statement is generated when the makePrismaSchema function runs.

This is my function parameters:

  const schema = makePrismaSchema({
    // Provide all the GraphQL types we've implemented
    types: [Query,Mutation,...typesList],

    // Configure the interface to Prisma
    prisma: {
      client: prisma,
      datamodelInfo: nexusPrismaSchema
    },

    // Specify where Nexus should put the generated files
    outputs: {
      schema: path.join(__dirname, './generated/schema.graphql'),
      typegen: path.join(__dirname, './generated/nexus.ts'),
    },

    // Configure nullability of input arguments: All arguments are non-nullable by default
    nonNullDefaults: {
      input: false,
      output: false,
    },

    // Configure automatic type resolution for the TS representations of the associated types
    typegenAutoConfig: {
      sources: [
        {
          source: path.join(__dirname, './interfaces/context.ts'),
          alias: 'types',
        },
      ],
      contextType: 'types.Context',
    },
  });

The problem is here:

typegenAutoConfig: {
      sources: [
        {
          source: path.join(__dirname, './interfaces/context.ts'),
          alias: 'types',
        },
      ],
      contextType: 'types.Context',
    },

The result on src/generated/nexus.tshas this import with the backslashes:

import * as types from "..\interfaces\context"
tgriesser commented 5 years ago

And what is the error you get?

israelglar commented 5 years ago

When node is trying to parse the string, it assumes the backslash is escape character, so what I get is:

src/generated/nexus.ts(6,24): error TS2307: Cannot find module '..interfacescontext'.
israelglar commented 5 years ago

I don't have that issue with my linux machine

tgriesser commented 5 years ago

Ah thanks, that makes more sense. Just need to add escaping for the \. I assume a JSON.stringify of the path will fix this. Will report back once it's fixed.