Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

vladinator1000
Copy link

@vladinator1000 vladinator1000 commented Jun 24, 2024

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

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as
    expected)
  • This change requires a documentation update

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

  • Unit test (packages/plugins/apollo-client/test/envelopSchemaLink.spec.ts)

Checklist:

  • I have followed the
    CONTRIBUTING doc and the
    style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented on my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Copy link

changeset-bot bot commented Jun 24, 2024

⚠️ No Changeset found

Latest commit: 47beb2e

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vladinator1000 vladinator1000 changed the title Apollo schema link integration Apollo Client - schema link integration Jun 24, 2024
export type ResolverContextFunction = (
operation: Operation,
) => ResolverContext | PromiseLike<ResolverContext>;
export type Options<PluginsType extends Optional<Plugin<any>>[]> = ReturnType<
Copy link
Author

@vladinator1000 vladinator1000 Jun 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +43 to +45
rootValue: {
execute: this.envelope.execute,
subscribe: this.envelope.subscribe,
Copy link
Author

@vladinator1000 vladinator1000 Jun 24, 2024

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();
Copy link
Collaborator

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';
Copy link
Collaborator

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: {
Copy link
Collaborator

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({
Copy link
Collaborator

@ardatan ardatan Jun 24, 2024

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.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants