question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Codegen issues in Docker context

See original GitHub issue

Hello!

So I’m building a Docker container of a Nuxt 3 (rc 11) project, and here are the related commands of the Dockerfile:

RUN yarn install --frozen-lockfile --non-interactive && yarn cache clean --all
RUN yarn build

However, my build fails at the first line, and I get the following errors:

Logs
$ nuxt prepare
 Nuxi 3.0.0-rc.11
 
  ERROR  (node:68) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
 (Use `node --trace-warnings ...` to show where the warning was created)
 
 
  ERROR 
         Failed to load schema from http://localhost:1337/graphql:
 
        fetch failed to http://localhost:1337/graphql
        TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async UrlLoader.load (file:///srv/node_modules/@graphql-tools/url-loader/esm/index.js:587:29)
    at async file:///srv/node_modules/@graphql-tools/load/esm/load-typedefs/load-file.js:11:39
    at async Promise.all (index 5)
    at async loadFile (file:///srv/node_modules/@graphql-tools/load/esm/load-typedefs/load-file.js:9:9)
    at async file:///srv/node_modules/@graphql-tools/load/esm/load-typedefs/collect-sources.js:144:25

        GraphQL Code Generator supports:
          - ES Modules and CommonJS exports (export as default or named export "schema")
          - Introspection JSON File
          - URL of GraphQL endpoint
          - Multiple files with type definitions (glob expression)
          - String in config file

        Try to use one of above options and run codegen again.

      

  Failed to load schema from http://localhost:1337/graphql:
  
  fetch failed to http://localhost:1337/graphql
  TypeError: fetch failed
  at Object.fetch (node:internal/deps/undici/undici:11118:11)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async UrlLoader.load (node_modules/@graphql-tools/url-loader/esm/index.js:587:29)
  at async node_modules/@graphql-tools/load/esm/load-typedefs/load-file.js:11:39
  at async Promise.all (index 5)
  at async loadFile (node_modules/@graphql-tools/load/esm/load-typedefs/load-file.js:9:9)
  at async node_modules/@graphql-tools/load/esm/load-typedefs/collect-sources.js:144:25
  
  GraphQL Code Generator supports:
  - ES Modules and CommonJS exports (export as default or named export "schema")
  - Introspection JSON File
  - URL of GraphQL endpoint
  - Multiple files with type definitions (glob expression)
  - String in config file
  
  Try to use one of above options and run codegen again.
  
  
  at executeCodegen (node_modules/@graphql-codegen/cli/esm/codegen.js:322:24)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async generate (node_modules/@graphql-codegen/cli/esm/generate-and-save.js:87:25)
  at async generate (node_modules/nuxt-graphql-client/dist/module.mjs:68:10)
  at async generateGqlTypes (node_modules/nuxt-graphql-client/dist/module.mjs:279:22)
  at async setup (node_modules/nuxt-graphql-client/dist/module.mjs:332:5)
  at async Object.normalizedModule (node_modules/@nuxt/kit/dist/index.mjs:637:5)
  at async installModule (node_modules/@nuxt/kit/dist/index.mjs:456:3)
  at async initNuxt (node_modules/nuxt/dist/index.mjs:1606:7)
  at async loadNuxt (node_modules/nuxt/dist/index.mjs:1635:5)
  at async loadNuxt (node_modules/@nuxt/kit/dist/index.mjs:732:19)
  at async Object.invoke (node_modules/nuxi/dist/chunks/prepare.mjs:30:18)
  at async _main (node_modules/nuxi/dist/cli.mjs:50:20)
  
  Error:
  Failed to load schema from http://localhost:1337/graphql:
  
  fetch failed to http://localhost:1337/graphql
  TypeError: fetch failed
  at Object.fetch (node:internal/deps/undici/undici:11118:11)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async UrlLoader.load (node_modules/@graphql-tools/url-loader/esm/index.js:587:29)
  at async node_modules/@graphql-tools/load/esm/load-typedefs/load-file.js:11:39
  at async Promise.all (index 5)
  at async loadFile (node_modules/@graphql-tools/load/esm/load-typedefs/load-file.js:9:9)
  at async node_modules/@graphql-tools/load/esm/load-typedefs/collect-sources.js:144:25
  
  GraphQL Code Generator supports:
  - ES Modules and CommonJS exports (export as default or named export "schema")
  - Introspection JSON File
  - URL of GraphQL endpoint
  - Multiple files with type definitions (glob expression)
  - String in config file
  
  Try to use one of above options and run codegen again.
  
  
  at loadSchema (node_modules/@graphql-codegen/cli/esm/load.js:42:15)
  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
  at async node_modules/@graphql-codegen/cli/esm/codegen.js:191:69
  at async node_modules/@graphql-codegen/cli/esm/codegen.js:190:56
  at async node_modules/@graphql-codegen/cli/esm/codegen.js:63:21
  at async Task.run (node_modules/listr2/dist/index.js:960:11)
  at async node_modules/p-map/index.js:57:22

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

I don’t know why i get the same error messages.

Please note that without a Docker context, everything works, but it somehow doesn’t when I’m running my commands outside of it.

My nuxt.config.ts file looks like so:

import { defineNuxtConfig } from 'nuxt/config'

export default defineNuxtConfig({
    modules: [
        'nuxt-graphql-client',
    ],

    runtimeConfig: {
        public: {
            APP_ENV: process.env.APP_ENV,
            PATRIMOINE_API: process.env.PATRIMOINE_API,
            GQL_HOST: process.env.GRAPHQL,
            API: process.env.API,
            URL: process.env.URL,
        }
    },

    css: ["@/assets/styles/main.scss"]
})

and my .graphqlconfig looks like so:

{
  "name": "Untitled GraphQL Schema",
  "schemaPath": "gql/schema.graphql",
  "extensions": {
    "endpoints": {
      "Default GraphQL Endpoint": {
        "url": "http://api:1337/graphql",
        "headers": {
          "user-agent": "JS GraphQL"
        },
        "introspect": true
      }
    }
  }
}

api:1337/graphql should be available but I can’t confirm since the Docker build fails before I can make sure of it is available, I managed to run a curl command with a graphql payload successfully. So I tried to give GraphQL an introspection schema (JSON and .graphql) but it seems it couldn’t find it in gql and at the project’s root.

Lastly, I tried to install nuxt-graphql-client@edge and to add the following line in the nuxt.config.ts as per #215:

'graphql-client'.codegen = false,

// Also tried with

'graphql-client': {
    codegen: false // type 'false' has no common property with the type GqlCodegen
},

What am doing wrong?

Thank you in advance

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Drillan767commented, Oct 18, 2022

@Diizzayy It was because I didn’t run yarn build afterwards, so you can just ignore it 😅

1reaction
Drillan767commented, Oct 18, 2022

Update

So, disabling the codegen works, however, it of course makes my GraphQL request not work at all afterwards (I should have guessed it haha).

However, I managed to generate a introspection schema, and told Nuxt to use it, so I could run my commands without trouble. I still have to find a way to automate it, but it’s way better than nothing.

So there seems to be a problem with how the codegen fetchs the schema while running yarn install.

Huge thanks for your support and for this plugin in any case!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use codegen inside docker container? #274 - GitHub
I'm trying to run python -m playwright codegen inside the container. My docker file is here. The goal is for the container to...
Read more >
Docker Context - Docker Documentation
This guide shows how contexts make it easy for a single Docker CLI to manage multiple Swarm clusters, multiple Kubernetes clusters, and multiple...
Read more >
Make one Docker image wait for another to finish before building
The yarn graphql file downloads the graphql schema from Hasura using graphql-codegen . Is it possible to orchestrate docker to wait for the ......
Read more >
PostGraphile | Usage - Schema Only
Calling a resolver from a resolver. You can issue GraphQL requests from various contexts, including within a resolver. To do so you need...
Read more >
Connect to remote Docker over SSH - Visual Studio Code
Use the Command Palette (Ctrl+Shift+P) to issue the Docker Contexts: Use command to activate the Docker context pointing to the remote machine.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found