piglovesyou / graphql-let

A webpack loader / babel-plugin / babel-plugin-macros / CLI / generated file manager of GraphQL code generator.
Apache License 2.0
454 stars 34 forks source link

Error: [ graphql-let ] Never supposed to be here. Please make an issue on GitHub #414

Open j-mcgregor opened 3 years ago

j-mcgregor commented 3 years ago

Trying to set up graphql-let from the with-typescript-graphql example from NextJS

My config has a few layers to it so I'm not sure where to begin.

I'm using Lerna, but I don't think that's the issue, the app ran fine before I tried adding graphql-let, but I guess I'll add my config

// next.config.js

const withTM = require('next-transpile-modules')
const withLess = require('@zeit/next-less')
const withCSS = require('@zeit/next-css')
const withPlugins = require('next-compose-plugins')
const lessToJS = require('less-vars-to-js')
const fs = require('fs')
const path = require('path')

const themeVariables = lessToJS(fs.readFileSync(path.resolve('./assets/antd-custom.less'), 'utf8'))

// fix: prevents error when .less files are required by node
if (typeof require !== 'undefined') {
    require.extensions['.less'] = (file) => {}
}

const nextConfig = {
    dir: '.',
    distDir: '.next',
    webpack: (config, { isServer, ...options }) => {
        if (options.isServer) {
            const antStyles = /antd\/.*?\/style.*?/
            const origExternals = [...config.externals]
            config.externals = [
                (context, request, callback) => {
                    if (request.match(antStyles)) return callback()
                    if (typeof origExternals[0] === 'function') {
                        origExternals[0](context, request, callback)
                    } else {
                        callback()
                    }
                },
                ...(typeof origExternals[0] === 'function' ? [] : origExternals)
            ]

            config.module.rules.unshift({
                test: antStyles,
                use: 'null-loader'
            })
        }

        config.module.rules.push({
            test: /\.graphql$/,
            exclude: /node_modules/,
            use: [
                { loader: 'babel-loader', options: { presets: ['@babel/preset-typescript', '@babel/preset-react'] } },
                { loader: 'graphql-let/loader' }
            ]
        })

        config.module.rules.push({
            test: /\.graphqls$/,
            exclude: /node_modules/,
            use: ['graphql-let/schema/loader']
        })

        config.module.rules.push({
            test: /\.ya?ml$/,
            type: 'json',
            use: 'yaml-loader'
        })

        return config
    }
}

module.exports = withPlugins(
    [
        [withCSS],
        [
            withLess,
            {
                lessLoaderOptions: {
                    javascriptEnabled: true,
                    modifyVars: themeVariables
                }
            }
        ],
        [
            withTM,
            {
                transpileModules: ['@lywe/components', '@lywe/shared']
            }
        ]
    ],
    nextConfig
)
# .graphql-let.yml

schema: '**/*.graphqls'
schemaEntrypoint: 'lib/type-defs.graphqls'
documents: '**/*.graphql'
plugins:
    - typescript
    - typescript-operations
    - typescript-react-apollo
cacheDir: __generated__

My errors:

➜ yarn codegen
yarn run v1.22.4
$ graphql-let
[ graphql-let ] Generating .d.ts...
[ graphql-let ] Never supposed to be here. Please make an issue on GitHub.Error: Never supposed to be here. Please make an issue on GitHub.
    at genDts (/Users/me/Development/Personal/project/node_modules/graphql-let/dist/lib/dts.js:72:15)
    at Object.processDtsForContext (/Users/me/Development/Personal/project/node_modules/graphql-let/dist/lib/dts.js:80:25)
    at gen (/Users/me/Development/Personal/project/node_modules/graphql-let/dist/gen.js:33:17)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
// next-env.d.ts

declare module '*.graphqls' {
    import { DocumentNode } from 'graphql'
    export default typeof DocumentNode
}

declare module '*.yml'
// tsconfig.json
{
  "compilerOptions": {
    "allowJs": true,
    "alwaysStrict": true,
    "composite": true,
    "declaration": true,
    "declarationMap": true,
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": ["dom", "dom.iterable", "esnext", "es2017"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "sourceMap": true,
    "strict": true,
    "target": "esnext"
  },
  "exclude": ["node_modules", ".next", "out"],
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.js"]
}

The __generated__/lib is being created but not the .graphql.d.ts beside all GraphQL documents

Any ideas? I can provide more info if you need

TaniaZaslon commented 3 years ago

Have the same problem. Have any solution for this?

piglovesyou commented 3 years ago

Hi, thanks for reporting all this. If you can make a simple reproduction repo, that'll be more than helpful.

j-mcgregor commented 3 years ago

Not sure I can, I abandoned the project I had this error in a while ago, sorry

TaniaZaslon commented 3 years ago

Hi, thanks for reporting all this. If you can make a simple reproduction repo, that'll be more than helpful.

@piglovesyou, Found differences between the data what being checked in this line https://github.com/piglovesyou/graphql-let/blob/db1fba47de9a4bafc1c7e18db955a09cdd8553c2/src/lib/dts.ts#L146

So in the end dtsContents is empty. And I receive this error "Never supposed to be here".

image

Platform: Windows.

My colleagues on Mac don't have this problem. Do you have an idea how to fix this?

piglovesyou commented 3 years ago

@TaniaZaslon Thank you so much for the clue, belatedly. Would you happen to have an idea of which GraphQL document causes it? It's great if we can have a sample project that reproduces the problem.