nuxt-graphql-client icon indicating copy to clipboard operation
nuxt-graphql-client copied to clipboard

Fetch Failed error - Failed to load schema

Open giuseppe-hex opened this issue 2 years ago • 2 comments

Hey,

Some context:

  • I'm able to get the starlink demo working
  • The query I'm trying to use works within postman and graphql-playground
  • The API is a local laravel app running in docker
  • Using Nuxt 3.0.0-rc.6
  • I've tried explicitly declaring the schema path and that hasn't helped
  • This works with the production url

I get the following error when running yarn dev:

image

nuxt-config.ts

...
  runtimeConfig: {
    public: {
      GQL_HOST: 'http://localhost/graphql',
      GQL_TOKEN_NAME: 'my_token_here'
    }
  },

  modules: ['@nuxtjs/tailwindcss', 'nuxt-graphql-client'],
...

data.gql (provided by b/e dev)

mutation acme_User() {
    getUser(id: 1) {
        first_name
        last_name
        created_at
    }
}

Let me know if there is anything else I can provide you with. Appreciate any help :)

giuseppe-hex avatar Aug 15 '22 15:08 giuseppe-hex

Apologies for the delayed reply here, have you checked to ensure that your api allows GraphQL introspection?

Diizzayy avatar Aug 18 '22 11:08 Diizzayy

Hello,

I'm running into similar problem. I'm using Laravel Lighthouse for my graphql api. It does allow introspection and introspection works in Apollo Studio. I get the same error log as above. Let me know if I can provide other details but my setup looks about the same as the one above.

Should I just provide a local generated schema via the client schema option?

John-Church avatar Sep 21 '22 22:09 John-Church

I got same issue. What's the solution?

Mnigos avatar Jan 18 '23 12:01 Mnigos

sorry for the late response, running into the same issue.

The problem is that there is no way to provide a Browser URL for a specific client (correct me if I'm wrong @Diizzayy)

Since you are using docker, your graphql API endpoint for your nuxt container (on SSR) is something like

http://yourservice:xxxx/graphql

but for your browser (assuming you are port forwarding) its

http://localhost:xxxx/graphql

One way to fix this would be to use the same URL using /etc/hosts or you it seems that changing the host dynamically works.

export default defineNuxtPlugin(async () => {
  if (process.client) {
    const runtimeConfig = useRuntimeConfig();
    useGqlHost(runtimeConfig.public.clientGqlHost);
  }
});

using a runtime variable like this in your nuxt config:

runtimeConfig: {
    public: {
      GQL_HOST: 'http://yourservice:xxxx/graphql',
      clientGqlHost: 'http://localhost:xxxx/graphql'
    },
  },

Hope it helps

PierreCavalet avatar Oct 31 '23 09:10 PierreCavalet