-
Notifications
You must be signed in to change notification settings - Fork 43
(do not merge) schemalink in app-dir-experiments #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
phryneas
wants to merge
1
commit into
main
Choose a base branch
from
pr/app-experiment-schemalink
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,11 @@ | ||
| import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client"; | ||
| import { ApolloClient, InMemoryCache } from "@apollo/client"; | ||
| import { SchemaLink } from "@apollo/client/link/schema"; | ||
| import { registerApolloClient } from "@apollo/experimental-nextjs-app-support/rsc"; | ||
| import { schema } from "./api/graphql/route"; | ||
|
|
||
| export const { getClient } = registerApolloClient(() => { | ||
| return new ApolloClient({ | ||
| cache: new InMemoryCache(), | ||
| link: new HttpLink({ | ||
| uri: "http://localhost:3000/api/graphql", | ||
| // you can disable result caching here if you want to | ||
| // (this does not work if you are rendering your page with `export const dynamic = "force-static"`) | ||
| // fetchOptions: { cache: "no-store" }, | ||
| }), | ||
| link: new SchemaLink({ schema }), | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,21 +6,18 @@ import { | |
| HttpLink, | ||
| SuspenseCache, | ||
| } from "@apollo/client"; | ||
| import { SchemaLink } from "@apollo/client/link/schema"; | ||
| import { | ||
| ApolloNextAppProvider, | ||
| NextSSRInMemoryCache, | ||
| SSRMultipartLink, | ||
| } from "@apollo/experimental-nextjs-app-support/ssr"; | ||
| import { setVerbosity } from "ts-invariant"; | ||
| import { schema } from "../api/graphql/route"; | ||
|
|
||
| setVerbosity("debug"); | ||
|
|
||
| function makeClient() { | ||
| const httpLink = new HttpLink({ | ||
| uri: "http://localhost:3000/api/graphql", | ||
| fetchOptions: { cache: "no-store" }, | ||
| }); | ||
|
|
||
| return new ApolloClient({ | ||
| cache: new NextSSRInMemoryCache(), | ||
| link: | ||
|
|
@@ -29,9 +26,14 @@ function makeClient() { | |
| new SSRMultipartLink({ | ||
| stripDefer: true, | ||
| }), | ||
| httpLink, | ||
| new SchemaLink({ | ||
| schema, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if we need to create a |
||
| }), | ||
| ]) | ||
| : httpLink, | ||
| : new HttpLink({ | ||
| uri: "http://localhost:3000/api/graphql", | ||
| fetchOptions: { cache: "no-store" }, | ||
| }), | ||
| }); | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering about how importing
schemahere could expose credentials,schemawith resolvers would need access to the DB driver, which in turn would need some credentials, we have a check forisServersoSchemaLinkis only used in the server side, but theschemais imported for both, meaning the bundle might end up with the driver setup in the client, and depending on how it's bundled it would have the credentials embedded somewhere, do you think I'm making a correct assumption here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From my experiences with the Nextjs bundler, I would assume that the
typeof window !== "undefined"check would removeSchemaLinkas well asschemafrom the client bundle shipped to the browser, but I'd be grateful if you could validate that further :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't validate, my setup uses Neo4j GraphQL schema, which is generated async, creating the wrapper with the schema makes it harder since the
makeClientfunction would need to be async, and Next.js complains about functional components that can't be async, sorry.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am dumb, dunno why I didn't think about this before but to solve my issue of schema generator being async, I could just wrap
makeClientinto an async factory, declare<ApolloWrapper>component as async and inside the component, await the factory to get themakeClientfunction to pass it toApolloNextAppProvider'smakeClientprop in a synchronous way, can't believe it took me this long to think about this solution...