apollo-client-nextjs icon indicating copy to clipboard operation
apollo-client-nextjs copied to clipboard

How does `SchemaLink` fit in here?

Open luchillo17 opened this issue 2 years ago • 4 comments

Grabbing the example for Next.js with-apollo-neo4j-graphql before the App router became stable it used to check isServer (typeof window === 'undefined') and based on that create a SchemaLink, which was supposed to use the same GraphQL query as a client instance, but be more efficient (I think it skips the HTTP request and queries the Schema directly, which in this example would be a Neo4jGraphQLSchema, not sure so don't quote me) but also limited to server-side components like SRC or SSR without the "use client" pragma (or whatever this metadata is called).

I'm wondering how this fits in the library since the README.md doesn't mention SchemaLink.

luchillo17 avatar Jun 07 '23 00:06 luchillo17

Hey @luchillo17 👋

First of all, take some of those examples with a grain of salt. I'm not sure how up-to-date those are, nor do I think those examples make use of this experimental library for proper RSC support. Some of them might still be fine, just know we haven't vetted those examples in quite some time.

Beyond that, I'm curious what you're looking for exactly when you say:

I'm wondering how this fits in the library

There is no reason you can't or shouldn't use SchemaLink, its more that it just wasn't mentioned in this README. We instead wanted to focus on how this library bridges the gap with RSC and the new React paradigms that Next.js utilizes in Next.js 13.

jerelmiller avatar Jun 07 '23 16:06 jerelmiller

Hi @jerelmiller, by wondering I would like to see a full example project with the SchemaLink & the app router in use, if it can effectively skip the API request then I would consider a good pattern to encourage.

luchillo17 avatar Jun 07 '23 19:06 luchillo17

You do bring up a great point here - I think it might make sense to have this integrated in one of our examples, as it also makes it possible to use the app directory for GraphQL api hosting. See #36.

phryneas avatar Jun 09 '23 10:06 phryneas

I see we have a new ApolloNextAppProvider, still have yet to see SchemaLink mentioned anywhere in the README.

Also, the neo4j-graphql example I mentioned in the description was deleted, shame, had to change the link to point to the deprecated-main branch.

Also for completeness' sake, this is the reason I can't use SchemaLink even if I wanted to test this, my schema is generated Async, which doesn't play nice with React for the wrapper:

export const getApolloServer = async (
  typeDefs: TypeDefinitions,
  neo4jDriverArgs?: Partial<Neo4jDriverArgs>
) => {
  if (apolloServer) {
    return apolloServer;
  }

  // This is the issue, can't create the schema async for NextSSRApolloClient
  // since `makeClient` doesn't accept async factory
  schema =
    schema ?? (await getNeo4jGraphQL(typeDefs, neo4jDriverArgs).getSchema());

  apolloServer = new ApolloServer({ schema });

  return apolloServer;
};

luchillo17 avatar Feb 03 '24 04:02 luchillo17