Skip to content

Is it possible to switch getInitialProps to getServerSideProps? #95

Open

Description

@newKeating

Well, since this withApollo hoc is using getInitialProps for ssr, there is a conflict when using getServerSideProps on a page component.


const Restaurant: NextPage<IProps> = ({ id }) => {
  console.log("id", id);
  const { data, loading } = useRestaurantQuery({
    variables: {
      input: {
        restaurantId: id,
      },
    },
  });

  console.log("loading", loading);
  console.log("data", data);
  if (loading) {
    return <div>Loading...</div>;
  }

  return (
    <div>
      restaurant
      <div>{data?.restaurant.result?.name}</div>
    </div>
  );
};

export default withApollo({ssr: true})(Restaurant);

export const getServerSideProps: GetServerSideProps = async (ctx) => {
  console.log("ctx", ctx);

  const { id } = ctx.query;
  if (!id) {
    return {
      props: {},
    };
  }

  return {
    props: { id: parseInt(id as string) },
  };
};

Screen Shot 2021-01-28 at 12 38 45 PM

So, I'm looking for a way to make withApollo hoc utlizing getServerSideProps for "ssr" mode.

Could there be a way to do that?

Activity

  1. besSejrani commented on Apr 24, 2021

    @besSejrani

    Yes, it would be great to have that change, since next has moved to version 10.1

  2. herbievine commented on Jun 3, 2021

    @herbievine

    Please introduce this @adamsoffer. But for now, is there a workaround or a temporary fix?

  3. AxelReid commented on Feb 20, 2023

    @AxelReid

    Is there any action on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions