nuxt-modules / apollo

Nuxt.js module to use Vue-Apollo. The Apollo integration for GraphQL.
https://apollo.nuxtjs.org
MIT License
956 stars 198 forks source link

Error: Apollo client with id default not found. Use an app.runWithContext() or provideApolloClient() if you are outside of a component setup. #638

Open adharshmk96 opened 5 days ago

adharshmk96 commented 5 days ago

Environment


Describe the bug

I'm getting 500 error when accessing a route that's using useQuery


500
Apollo client with id default not found. Use an app.runWithContext() or provideApolloClient() if you are outside of a component setup.

at resolveClient (http://localhost:3001/_nuxt/node_modules/@vue/apollo-composable/dist/index.mjs?v=493fcafe:58:13)
at getClient (http://localhost:3001/_nuxt/node_modules/@vue/apollo-composable/dist/index.mjs?v=493fcafe:296:12)
at start (http://localhost:3001/_nuxt/node_modules/@vue/apollo-composable/dist/index.mjs?v=493fcafe:317:20)
at useQueryImpl (http://localhost:3001/_nuxt/node_modules/@vue/apollo-composable/dist/index.mjs?v=493fcafe:589:5)
at useQuery (http://localhost:3001/_nuxt/node_modules/@vue/apollo-composable/dist/index.mjs?v=493fcafe:236:10)
at setup (http://localhost:3001/_nuxt/pages/member/overview.js:68:45)
at callWithErrorHandling (http://localhost:3001/_nuxt/node_modules/.pnpm/@vue+runtime-core@3.5.13/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js?v=493fcafe:197:19)
at setupStatefulComponent (http://localhost:3001/_nuxt/node_modules/.pnpm/@vue+runtime-core@3.5.13/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js?v=493fcafe:7923:25)
at setupComponent (http://localhost:3001/_nuxt/node_modules/.pnpm/@vue+runtime-core@3.5.13/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js?v=493fcafe:7884:36)
at mountComponent (http://localhost:3001/_nuxt/node_modules/.pnpm/@vue+runtime-core@3.5.13/node_modules/@vue/runtime-core/dist/runtime-core.esm-bundler.js?v=493fcafe:5240:7)

the code I'm using is

const query = gql`
  query {
    activeTrainingProgram {
      id
      name
      trainingWeek {
        day
        exercises {
          exerciseName
          weight
          sets
          reps
        }
      }
    }
  }
`;

const sampleData = {
  id: 1,
  name: "Sample Training Program",
  trainingWeek: {
    day: "Monday",
    exercises: [
      {
        exerciseName: "Sample Exercise",
        weight: 50,
        sets: 3,
        reps: 10,
      },
    ],
  },
};

const { result, loading, error, refetch } = useQuery(query);

in nuxt config I've configured it like this

modules: [
    "@nuxtjs/apollo",
    "@pinia/nuxt",
    "@nuxt/ui",
  ],
  apollo: {
    clients: {
      default: {
        httpEndpoint: 'http://localhost:8080/query',
        httpLinkOptions: {
          credentials: 'include',
        }
      }
    },
  }

Expected behaviour

I'm expecting the page to load properly without errors.

Reproduction

No response

Additional context

No response

Logs

adharshmk96 commented 5 days ago

useAsyncQuery works well

const query = gql`
  query {
    activeTrainingProgram {
      id
      name
      trainingWeek {
        day
        exercises {
          exerciseName
          weight
          sets
          reps
        }
      }
    }
  }
`;

const sampleData = {
  id: 1,
  name: "Sample Training Program",
  trainingWeek: {
    day: "Monday",
    exercises: [
      {
        exerciseName: "Sample Exercise",
        weight: 50,
        sets: 3,
        reps: 10,
      },
    ],
  },
};

const { data } = await useAsyncQuery(query);