-
Notifications
You must be signed in to change notification settings - Fork 128
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
Apollo Client - schema link integration #2257
base: main
Are you sure you want to change the base?
Conversation
|
export type ResolverContextFunction = ( | ||
operation: Operation, | ||
) => ResolverContext | PromiseLike<ResolverContext>; | ||
export type Options<PluginsType extends Optional<Plugin<any>>[]> = ReturnType< |
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.
rootValue: { | ||
execute: this.envelope.execute, | ||
subscribe: this.envelope.subscribe, |
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 not sure what to put here. Lee Byron says
The root value represents the "top" of your metaphorical graph of data, and is useful to include functions or data to help resolve the root fields in your schema.
I've personally never had the need to use rootValue
. It seems like Apollo's SchemaLink has it as an option
const getEnveloped = envelop({ | ||
plugins: [useEngine(graphqlJs), useSchema(schema)], | ||
}); | ||
const envelope = getEnveloped(); |
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 think getEnveloped
should be called per operation instead of once.
Because the lifecycle in Envelop is handled per operation. So it would be better to call it inside the link.
@@ -0,0 +1,42 @@ | |||
import * as graphqlJs from 'graphql'; | |||
import { ApolloClient, gql, InMemoryCache } from '@apollo/client'; | |||
import { EnvelopSchemaLink } from '@envelop/apollo-client'; |
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.
Let's call it only EnvelopLink
.
EnvelopSchema seems extra :)
return this.envelope.execute({ | ||
schema: this.envelope.schema, | ||
document: operation.query, | ||
rootValue: { |
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.
We don't need this I guess.
return { errors: validationErrors }; | ||
} | ||
|
||
return this.envelope.execute({ |
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.
Do you think we can also support subscribe
?
Also keep on mind that execute
can return AsyncIterable.
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.
This can be similar to this one;
https://github.com/ardatan/graphql-mesh/blob/master/packages/legacy/apollo-link/src/index.ts
Description
Useful for server-side rendering that avoids network calls, if you're rendering on the same server that the GraphQL API runs on.
#2256
Type of change
expected)
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can
reproduce. Please also list any relevant details for your test configuration
Checklist:
CONTRIBUTING doc and the
style guidelines of this project