Apollo Client - schema link integration#2257
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.
| rootValue: { | ||
| execute: this.envelope.execute, | ||
| subscribe: this.envelope.subscribe, |
There was a problem hiding this comment.
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.
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.
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.
We don't need this I guess.
| return { errors: validationErrors }; | ||
| } | ||
|
|
||
| return this.envelope.execute({ |
There was a problem hiding this comment.
Do you think we can also support subscribe ?
Also keep on mind that execute can return AsyncIterable.
There was a problem hiding this comment.
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