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.

Getting Stuck with Apollo

See original GitHub issue

Dear @brillout,

Thank you for this plugin, it looks very promising.

update: seems to be working perfectly now!

If you have time, would you mind creating a very basic example using apollo client? I am probably doing something stupid but I don’t think I can figure it out on my own.

// apollo/index.ts
import 'cross-fetch/polyfill';
import { ApolloClient } from '@apollo/client'
import { InvalidationPolicyCache } from 'apollo-invalidation-policies';

export const client = new ApolloClient({
  cache: new InvalidationPolicyCache({}),
  uri: 'https://countries.trevorblades.com'
})
// pages/tests/index.page.server.ts
import { gql } from '@apollo/client'
import {client} from '../../apollo'

export { addContextProps }
export { setPageProps }

export const LIST_COUNTRIES = gql`
  {
    countries {
      name
      code
    }
  }
`;

async function addContextProps({ contextProps }) {
  const response = await client.query({query: LIST_COUNTRIES})

  return { countries: response.data.countries }
}

function setPageProps({ contextProps: { countries } }) {
  return { countries }
}
// pages/tests/index.page.tsx
import React from "react";
import { useQuery } from '@apollo/client'
import "./index.css";
import {client} from '../../apollo'
import {LIST_COUNTRIES} from './index.page.server'

export { Page };

function Page({countries}) {
  const {data} = useQuery(LIST_COUNTRIES, {client});
  console.log('countries', countries) // This is not working
  console.log('data', data) // This works 
  return (
    <>
      <h1>TEsts</h1>
      <p>A okay text.</p>
    </>
  );
}

Thank you very much,

Lydia

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
LydiaFcommented, Jun 4, 2021

Hey @felixakiragreen, I deleted the last comment mistakenly if you read it, if you didnt: no good news from me. We couldn’t fix it in the end and I had spent ages refactoring so I didn’t get the circ dep warnings, but it still didn’t work. I can’t remember what exact the issue was but we figured it was probably the ssr circular dep issue in the vite repo and we decided, with heavy hearts, to let ssr go until it was fixed!

https://github.com/vitejs/vite/issues/2258

1reaction
brilloutcommented, Mar 15, 2021

Make sure to use await:

await getDataFromTree(Page).then((_pageHtml)

Otherwise pageHtml won’t get set.

Also you should initialize the Apollo client only once at startup time, instead of initializing it on every HTTP request.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Headphone Tip Stuck in Apollo - Gearspace.com
Little bit of a situation, a dodgy headphone adaptor has broken off inside the headphone output of my Apollo Quad (normal one, not...
Read more >
A P O L L O - Wait (Stuck with Me) - YouTube
A P O L L O - Wait ( Stuck with Me) Video created by Music Waves Media Subscribe for more videos This...
Read more >
Cables stuck in Twin | UAD, Apollo, and LUNA Forums
I have two 1/4 line cables in the combo jack of my Apollo Twin. For some reason they don't want to come out....
Read more >
Apollo sometimes gets stuck loading content : r/apolloapp
I am experiencing the same issue several times a day. To work around this I force quit the app and restart it.
Read more >
What If We Got Stuck on the Moon? - Literary Hub
Apollo 11 astronauts Neil Armstrong and Buzz Aldrin deliberately refused to contemplate what might happen if the Eagle's ascent engine failed on ...
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